Skip to content

Commit

Permalink
Update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
zankich committed Jul 9, 2014
1 parent 97a1dc6 commit 7eec236
Show file tree
Hide file tree
Showing 52 changed files with 500 additions and 248 deletions.
10 changes: 7 additions & 3 deletions examples/ardrone.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,19 @@ func main() {

work := func() {
drone.TakeOff()
gobot.On(drone.Events["Flying"], func(data interface{}) {
gobot.On(drone.Event("Flying"), func(data interface{}) {
gobot.After(3*time.Second, func() {
drone.Land()
})
})
}

gbot.Robots = append(gbot.Robots,
gobot.NewRobot("drone", []gobot.Connection{ardroneAdaptor}, []gobot.Device{drone}, work))
robot := gobot.NewRobot("drone",
[]gobot.Connection{ardroneAdaptor},
[]gobot.Device{drone},
work,
)
gbot.AddRobot(robot)

gbot.Start()
}
13 changes: 9 additions & 4 deletions examples/ardrone_face_tracking.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ func main() {
detect := false
drone.TakeOff()
var image *cv.IplImage
gobot.On(camera.Events["Frame"], func(data interface{}) {
gobot.On(camera.Event("frame"), func(data interface{}) {
image = data.(*cv.IplImage)
if detect == false {
window.ShowImage(image)
}
})
gobot.On(drone.Events["Flying"], func(data interface{}) {
gobot.On(drone.Event("flying"), func(data interface{}) {
gobot.After(1*time.Second, func() { drone.Up(0.2) })
gobot.After(2*time.Second, func() { drone.Hover() })
gobot.After(5*time.Second, func() {
Expand Down Expand Up @@ -69,8 +69,13 @@ func main() {
})
}

gbot.Robots = append(gbot.Robots,
gobot.NewRobot("face", []gobot.Connection{ardroneAdaptor}, []gobot.Device{window, camera, drone}, work))
robot := gobot.NewRobot("face",
[]gobot.Connection{ardroneAdaptor},
[]gobot.Device{window, camera, drone},
work,
)

gbot.AddRobot(robot)

gbot.Start()
}
23 changes: 14 additions & 9 deletions examples/ardrone_ps3.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,34 +27,34 @@ func main() {
rightStick := pair{x: 0, y: 0}
leftStick := pair{x: 0, y: 0}

gobot.On(joystick.Events["square_press"], func(data interface{}) {
gobot.On(joystick.Event("square_press"), func(data interface{}) {
drone.TakeOff()
})
gobot.On(joystick.Events["triangle_press"], func(data interface{}) {
gobot.On(joystick.Event("triangle_press"), func(data interface{}) {
drone.Hover()
})
gobot.On(joystick.Events["x_press"], func(data interface{}) {
gobot.On(joystick.Event("x_press"), func(data interface{}) {
drone.Land()
})
gobot.On(joystick.Events["left_x"], func(data interface{}) {
gobot.On(joystick.Event("left_x"), func(data interface{}) {
val := float64(data.(int16))
if leftStick.x != val {
leftStick.x = val
}
})
gobot.On(joystick.Events["left_y"], func(data interface{}) {
gobot.On(joystick.Event("left_y"), func(data interface{}) {
val := float64(data.(int16))
if leftStick.y != val {
leftStick.y = val
}
})
gobot.On(joystick.Events["right_x"], func(data interface{}) {
gobot.On(joystick.Event("right_x"), func(data interface{}) {
val := float64(data.(int16))
if rightStick.x != val {
rightStick.x = val
}
})
gobot.On(joystick.Events["right_y"], func(data interface{}) {
gobot.On(joystick.Event("right_y"), func(data interface{}) {
val := float64(data.(int16))
if rightStick.y != val {
rightStick.y = val
Expand Down Expand Up @@ -100,8 +100,13 @@ func main() {
})
}

gbot.Robots = append(gbot.Robots,
gobot.NewRobot("ardrone", []gobot.Connection{joystickAdaptor, ardroneAdaptor}, []gobot.Device{joystick, drone}, work))
robot := gobot.NewRobot("ardrone",
[]gobot.Connection{joystickAdaptor, ardroneAdaptor},
[]gobot.Device{joystick, drone},
work,
)

gbot.AddRobot(robot)

gbot.Start()
}
Expand Down
12 changes: 9 additions & 3 deletions examples/beaglebone_blink.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,21 @@ func main() {
gbot := gobot.NewGobot()

beagleboneAdaptor := beaglebone.NewBeagleboneAdaptor("beaglebone")
led := gpio.NewLedDriver(beagleboneAdaptor, "led", "P9_12")
led := gpio.NewLedDriver("led", beagleboneAdaptor, "P9_12")

work := func() {
gobot.Every(1*time.Second, func() {
led.Toggle()
})
}

gbot.Robots = append(gbot.Robots,
gobot.NewRobot("blinkBot", []gobot.Connection{beagleboneAdaptor}, []gobot.Device{led}, work))
robot := gobot.NewRobot("blinkBot",
[]gobot.Connection{beagleboneAdaptor},
[]gobot.Device{led},
work,
)

gbot.AddRobot(robot)

gbot.Start()
}
10 changes: 8 additions & 2 deletions examples/beaglebone_blinkm.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ func main() {
})
}

gbot.Robots = append(gbot.Robots,
gobot.NewRobot("blinkmBot", []gobot.Connection{beagleboneAdaptor}, []gobot.Device{blinkm}, work))
robot := gobot.NewRobot("blinkmBot",
[]gobot.Connection{beagleboneAdaptor},
[]gobot.Device{blinkm},
work,
)

gbot.AddRobot(robot)

gbot.Start()
}
12 changes: 8 additions & 4 deletions examples/beaglebone_button.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,20 @@ func main() {
button := gpio.NewButtonDriver(beagleboneAdaptor, "button", "P8_9")

work := func() {
gobot.On(button.Events["push"], func(data interface{}) {
gobot.On(button.Event("push"), func(data interface{}) {
fmt.Println("button pressed")
})

gobot.On(button.Events["release"], func(data interface{}) {
gobot.On(button.Event("release"), func(data interface{}) {
fmt.Println("button released")
})
}

gbot.Robots = append(gbot.Robots,
gobot.NewRobot("buttonBot", []gobot.Connection{beagleboneAdaptor}, []gobot.Device{button}, work))
robot := gobot.NewRobot("buttonBot",
[]gobot.Connection{beagleboneAdaptor},
[]gobot.Device{button},
work,
)
gbot.AddRobot(robot)
gbot.Start()
}
10 changes: 8 additions & 2 deletions examples/beaglebone_direct_pin.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ func main() {
})
}

gbot.Robots = append(gbot.Robots,
gobot.NewRobot("pinBot", []gobot.Connection{beagleboneAdaptor}, []gobot.Device{led}, work))
robot := gobot.NewRobot("pinBot",
[]gobot.Connection{beagleboneAdaptor},
[]gobot.Device{led},
work,
)

gbot.AddRobot(robot)

gbot.Start()
}
12 changes: 9 additions & 3 deletions examples/beaglebone_led_brightness.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
func main() {
gbot := gobot.NewGobot()
beagleboneAdaptor := beaglebone.NewBeagleboneAdaptor("beaglebone")
led := gpio.NewLedDriver(beagleboneAdaptor, "led", "P9_14")
led := gpio.NewLedDriver("led", beagleboneAdaptor, "P9_14")

work := func() {
brightness := uint8(0)
Expand All @@ -25,7 +25,13 @@ func main() {
})
}

gbot.Robots = append(gbot.Robots,
gobot.NewRobot("pwmBot", []gobot.Connection{beagleboneAdaptor}, []gobot.Device{led}, work))
robot := gobot.NewRobot("pwmBot",
[]gobot.Connection{beagleboneAdaptor},
[]gobot.Device{led},
work,
)

gbot.AddRobot(robot)

gbot.Start()
}
22 changes: 13 additions & 9 deletions examples/beaglebone_led_brightness_with_analog_input.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,31 @@ import (
"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/platforms/beaglebone"
"github.com/hybridgroup/gobot/platforms/gpio"
"time"
)

func main() {
gbot := gobot.NewGobot()
beagleboneAdaptor := beaglebone.NewBeagleboneAdaptor("beaglebone")

beagleboneAdaptor := beaglebone.NewBeagleboneAdaptor("beaglebone")
sensor := gpio.NewAnalogSensorDriver(beagleboneAdaptor, "sensor", "P9_33")
led := gpio.NewLedDriver(beagleboneAdaptor, "led", "P9_14")
led := gpio.NewLedDriver("led", beagleboneAdaptor, "P9_14")

work := func() {
gobot.Every(100*time.Millisecond, func() {
val := sensor.Read()
brightness := uint8(gobot.ToScale(gobot.FromScale(float64(val), 0, 1024), 0, 255))
fmt.Println("sensor", val)
gobot.On(sensor.Event("data"), func(data interface{}) {
brightness := uint8(gobot.ToScale(gobot.FromScale(float64(data.(int)), 0, 1024), 0, 255))
fmt.Println("sensor", data)
fmt.Println("brightness", brightness)
led.Brightness(brightness)
})
}

gbot.Robots = append(gbot.Robots,
gobot.NewRobot("sensorBot", []gobot.Connection{beagleboneAdaptor}, []gobot.Device{sensor, led}, work))
robot := gobot.NewRobot("sensorBot",
[]gobot.Connection{beagleboneAdaptor},
[]gobot.Device{sensor, led},
work,
)

gbot.AddRobot(robot)

gbot.Start()
}
14 changes: 10 additions & 4 deletions examples/beaglebone_makey_button.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,22 @@ func main() {
button := gpio.NewMakeyButtonDriver(beagleboneAdaptor, "button", "P8_9")

work := func() {
gobot.On(button.Events["push"], func(data interface{}) {
gobot.On(button.Event("push"), func(data interface{}) {
fmt.Println("button pressed")
})

gobot.On(button.Events["release"], func(data interface{}) {
gobot.On(button.Event("release"), func(data interface{}) {
fmt.Println("button released")
})
}

gbot.Robots = append(gbot.Robots,
gobot.NewRobot("makeyBot", []gobot.Connection{beagleboneAdaptor}, []gobot.Device{button}, work))
robot := gobot.NewRobot("makeyBot",
[]gobot.Connection{beagleboneAdaptor},
[]gobot.Device{button},
work,
)

gbot.AddRobot(robot)

gbot.Start()
}
10 changes: 8 additions & 2 deletions examples/beaglebone_servo.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ func main() {
})
}

gbot.Robots = append(gbot.Robots,
gobot.NewRobot("servoBot", []gobot.Connection{beagleboneAdaptor}, []gobot.Device{servo}, work))
robot := gobot.NewRobot("servoBot",
[]gobot.Connection{beagleboneAdaptor},
[]gobot.Device{servo},
work,
)

gbot.AddRobot(robot)

gbot.Start()
}
12 changes: 9 additions & 3 deletions examples/digispark_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@ import (

func main() {
gbot := gobot.NewGobot()

api.NewAPI(gbot).Start()

digisparkAdaptor := digispark.NewDigisparkAdaptor("Digispark")
led := gpio.NewLedDriver(digisparkAdaptor, "led", "0")
led := gpio.NewLedDriver("led", digisparkAdaptor, "0")

robot := gobot.NewRobot("digispark",
[]gobot.Connection{digisparkAdaptor},
[]gobot.Device{led},
)

gbot.AddRobot(robot)

gbot.Robots = append(gbot.Robots,
gobot.NewRobot("digispark", []gobot.Connection{digisparkAdaptor}, []gobot.Device{led}, nil))
gbot.Start()
}
12 changes: 9 additions & 3 deletions examples/digispark_blink.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,21 @@ import (
func main() {
gbot := gobot.NewGobot()
digisparkAdaptor := digispark.NewDigisparkAdaptor("Digispark")
led := gpio.NewLedDriver(digisparkAdaptor, "led", "0")
led := gpio.NewLedDriver("led", digisparkAdaptor, "0")

work := func() {
gobot.Every(1*time.Second, func() {
led.Toggle()
})
}

gbot.Robots = append(gbot.Robots,
gobot.NewRobot("blinkBot", []gobot.Connection{digisparkAdaptor}, []gobot.Device{led}, work))
robot := gobot.NewRobot("blinkBot",
[]gobot.Connection{digisparkAdaptor},
[]gobot.Device{led},
work,
)

gbot.AddRobot(robot)

gbot.Start()
}
12 changes: 9 additions & 3 deletions examples/digispark_led_brightness.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func main() {
gbot := gobot.NewGobot()

digisparkAdaptor := digispark.NewDigisparkAdaptor("digispark")
led := gpio.NewLedDriver(digisparkAdaptor, "led", "0")
led := gpio.NewLedDriver("led", digisparkAdaptor, "0")

work := func() {
brightness := uint8(0)
Expand All @@ -26,7 +26,13 @@ func main() {
})
}

gbot.Robots = append(gbot.Robots,
gobot.NewRobot("pwmBot", []gobot.Connection{digisparkAdaptor}, []gobot.Device{led}, work))
robot := gobot.NewRobot("pwmBot",
[]gobot.Connection{digisparkAdaptor},
[]gobot.Device{led},
work,
)

gbot.AddRobot(robot)

gbot.Start()
}
Loading

0 comments on commit 7eec236

Please sign in to comment.