forked from hybridgroup/gobot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sprkplus: add custom collision default params
Signed-off-by: deadprogram <[email protected]>
- Loading branch information
1 parent
6941810
commit 0263b9c
Showing
3 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// +build example | ||
// | ||
// Do not build by default. | ||
|
||
/* | ||
How to run | ||
Pass the Bluetooth address or name as the first param: | ||
go run examples/bb8-collision.go BB-1234 | ||
NOTE: sudo is required to use BLE in Linux | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"gobot.io/x/gobot" | ||
"gobot.io/x/gobot/platforms/ble" | ||
"gobot.io/x/gobot/platforms/sphero/sprkplus" | ||
) | ||
|
||
func main() { | ||
bleAdaptor := ble.NewClientAdaptor(os.Args[1]) | ||
ball := sprkplus.NewDriver(bleAdaptor) | ||
|
||
work := func() { | ||
ball.On("collision", func(data interface{}) { | ||
fmt.Printf("collision detected = %+v \n", data) | ||
ball.SetRGB(255, 0, 0) | ||
}) | ||
|
||
ball.SetRGB(0, 255, 0) | ||
ball.Roll(80, 0) | ||
} | ||
|
||
robot := gobot.NewRobot("sprkplus", | ||
[]gobot.Connection{bleAdaptor}, | ||
[]gobot.Device{ball}, | ||
work, | ||
) | ||
|
||
robot.Start() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package bb8 | ||
|
||
import "gobot.io/x/gobot/platforms/sphero" | ||
|
||
// DefaultCollisionConfig returns a CollisionConfig with sensible collision defaults | ||
func DefaultCollisionConfig() sphero.CollisionConfig { | ||
return sphero.CollisionConfig{ | ||
Method: 0x01, | ||
Xt: 0x20, | ||
Yt: 0x20, | ||
Xs: 0x20, | ||
Ys: 0x20, | ||
Dead: 0x01, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package sprkplus | ||
|
||
import "gobot.io/x/gobot/platforms/sphero" | ||
|
||
// DefaultCollisionConfig returns a CollisionConfig with sensible collision defaults | ||
func DefaultCollisionConfig() sphero.CollisionConfig { | ||
return sphero.CollisionConfig{ | ||
Method: 0x01, | ||
Xt: 0x20, | ||
Yt: 0x20, | ||
Xs: 0x20, | ||
Ys: 0x20, | ||
Dead: 0x01, | ||
} | ||
} |