Skip to content

Commit

Permalink
Merge remote-tracking branch 'ardan-bkennedy/master' into sphero_enha…
Browse files Browse the repository at this point in the history
…ncements

Conflicts:
	platforms/sphero/sphero_driver.go
  • Loading branch information
zankich committed Dec 25, 2014
2 parents da566bc + 8856070 commit f043f98
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
21 changes: 18 additions & 3 deletions platforms/sphero/sphero_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type SpheroDriver struct {
responseChannel chan []uint8
gobot.Eventer
gobot.Commander
cdConfigured bool // Indicates if collision detection is configured.
}

// NewSpheroDriver returns a new SpheroDriver given a SpheroAdaptor and name.
Expand All @@ -61,6 +62,7 @@ func NewSpheroDriver(a *SpheroAdaptor, name string) *SpheroDriver {
s.AddEvent(Error)
s.AddEvent(ChannelCollisions)
s.AddEvent(ChannelSensordata)

s.AddCommand("SetRGB", func(params map[string]interface{}) interface{} {
r := uint8(params["r"].(float64))
g := uint8(params["g"].(float64))
Expand Down Expand Up @@ -182,7 +184,17 @@ func (s *SpheroDriver) Start() (errs []error) {
}
}()

s.configureCollisionDetection()
if !s.cdConfigured {
fmt.Println("Using default collision detection parameters...")
s.ConfigureCollisionDetection(CollisionConfig{
Method: 0x01,
Xt: 0x80,
Yt: 0x80,
Xs: 0x80,
Ys: 0x80,
Dead: 0x60,
})
}
s.enableStopOnDisconnect()

return
Expand Down Expand Up @@ -272,8 +284,11 @@ func (s *SpheroDriver) Stop() {
s.Roll(0, 0)
}

func (s *SpheroDriver) configureCollisionDetection() {
s.packetChannel <- s.craftPacket([]uint8{0x01, 0x40, 0x40, 0x50, 0x50, 0x60}, 0x02, 0x12)
// ConfigureCollisionDetection configures the sensitivity of the detection.
// https://github.com/orbotix/DeveloperResources/blob/master/docs/Collision%20detection%201.2.pdf.
func (s *SpheroDriver) ConfigureCollisionDetection(cc CollisionConfig) {
s.cdConfigured = true
s.packetChannel <- s.craftPacket([]uint8{cc.Method, cc.Xt, cc.Yt, cc.Xs, cc.Ys, cc.Dead}, 0x02, 0x12)
}

func (s *SpheroDriver) enableStopOnDisconnect() {
Expand Down
22 changes: 22 additions & 0 deletions platforms/sphero/sphero_packets.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,25 @@ type DataStreamingPacket struct {
// 0080 0000h Velocity Y -32768 to 32767 mm/s
VeloY int16
}

// CollisionConfig provides configuration for the collision detection alogorithm.
type CollisionConfig struct {
// Detection method type to use. Methods 01h and 02h are supported as
// of FW ver 1.42. Use 00h to completely disable this service.
Method uint8
// An 8-bit settable threshold for the X (left/right) axes of Sphero.
// A value of 00h disables the contribution of that axis.
Xt uint8
// An 8-bit settable threshold for the Y (front/back) axes of Sphero.
// A value of 00h disables the contribution of that axis.
Yt uint8
// An 8-bit settable speed value for the X axes. This setting is ranged
// by the speed, then added to Xt to generate the final threshold value.
Xs uint8
// An 8-bit settable speed value for the Y axes. This setting is ranged
// by the speed, then added to Yt to generate the final threshold value.
Ys uint8
// An 8-bit post-collision dead time to prevent retriggering; specified
// in 10ms increments.
Dead uint8
}

0 comments on commit f043f98

Please sign in to comment.