func main() { gbot := gobot.NewGobot() joystickAdaptor := joystick.NewJoystickAdaptor("ps3") joystick := joystick.NewJoystickDriver(joystickAdaptor, "ps3", "./platforms/joystick/configs/dualshock3.json", ) work := func() { gobot.On(joystick.Event("square_press"), func(data interface{}) { fmt.Println("square_press") }) gobot.On(joystick.Event("square_release"), func(data interface{}) { fmt.Println("square_release") }) gobot.On(joystick.Event("triangle_press"), func(data interface{}) { fmt.Println("triangle_press") }) gobot.On(joystick.Event("triangle_release"), func(data interface{}) { fmt.Println("triangle_release") }) gobot.On(joystick.Event("left_x"), func(data interface{}) { fmt.Println("left_x", data) }) gobot.On(joystick.Event("left_y"), func(data interface{}) { fmt.Println("left_y", data) }) gobot.On(joystick.Event("right_x"), func(data interface{}) { fmt.Println("right_x", data) }) gobot.On(joystick.Event("right_y"), func(data interface{}) { fmt.Println("right_y", data) }) } robot := gobot.NewRobot("joystickBot", []gobot.Connection{joystickAdaptor}, []gobot.Device{joystick}, work, ) gbot.AddRobot(robot) gbot.Start() }
func main() { gbot := gobot.NewGobot() joystickAdaptor := joystick.NewJoystickAdaptor("xbox360") joystick := joystick.NewJoystickDriver(joystickAdaptor, "xbox360", "./platforms/joystick/configs/joystick/configs/xbox360_power_a_mini_proex.json", ) work := func() { gobot.On(joystick.Event("a_press"), func(data interface{}) { fmt.Println("a_press") }) gobot.On(joystick.Event("a_release"), func(data interface{}) { fmt.Println("a_release") }) gobot.On(joystick.Event("b_press"), func(data interface{}) { fmt.Println("b_press") }) gobot.On(joystick.Event("b_release"), func(data interface{}) { fmt.Println("b_release") }) gobot.On(joystick.Event("up"), func(data interface{}) { fmt.Println("up", data) }) gobot.On(joystick.Event("down"), func(data interface{}) { fmt.Println("down", data) }) gobot.On(joystick.Event("left"), func(data interface{}) { fmt.Println("left", data) }) gobot.On(joystick.Event("right"), func(data interface{}) { fmt.Println("right", data) }) gobot.On(joystick.Event("left_x"), func(data interface{}) { fmt.Println("left_x", data) }) gobot.On(joystick.Event("left_y"), func(data interface{}) { fmt.Println("left_y", data) }) gobot.On(joystick.Event("right_x"), func(data interface{}) { fmt.Println("right_x", data) }) gobot.On(joystick.Event("right_y"), func(data interface{}) { fmt.Println("right_y", data) }) } robot := gobot.NewRobot("joystickBot", []gobot.Connection{joystickAdaptor}, []gobot.Device{joystick}, work, ) gbot.AddRobot(robot) gbot.Start() }
func main() { gbot := gobot.NewGobot() m := mqtt.NewMqttAdaptor("mqtt", "tcp://192.168.0.90:1883", "gcs") ardroneAdaptor := ardrone.NewArdroneAdaptor("Drone", "192.168.0.40") joystickAdaptor := joystick.NewJoystickAdaptor("ps3") joystick := joystick.NewJoystickDriver(joystickAdaptor, "ps3", "./dualshock3.json", ) drone := ardrone.NewArdroneDriver(ardroneAdaptor, "Drone") work := func() { dgram := url.Values{ "name": {"gcs"}, "dispenser_id": {"3"}, "drink_id": {"0"}, "event": {"available"}, "details": {"drone"}, } m.Publish("gcs", []byte(dgram.Encode())) offset := 32767.0 rightStick := pair{x: 0, y: 0} leftStick := pair{x: 0, y: 0} m.On("drone", func(data []byte) { dgram.Set("event", "delivery complete") m.Publish("gcs", []byte(dgram.Encode())) }) gobot.On(joystick.Event("circle_press"), func(data interface{}) { fmt.Println("Drop!") m.Publish("drop", []byte{}) }) gobot.On(joystick.Event("square_press"), func(data interface{}) { drone.TakeOff() dgram.Set("event", "en route") m.Publish("gcs", []byte(dgram.Encode())) }) gobot.On(joystick.Event("triangle_press"), func(data interface{}) { drone.Hover() }) gobot.On(joystick.Event("x_press"), func(data interface{}) { drone.Land() dgram.Set("event", "available") m.Publish("gcs", []byte(dgram.Encode())) }) gobot.On(joystick.Event("left_x"), func(data interface{}) { val := float64(data.(int16)) if leftStick.x != val { leftStick.x = val } }) gobot.On(joystick.Event("left_y"), func(data interface{}) { val := float64(data.(int16)) if leftStick.y != val { leftStick.y = val } }) gobot.On(joystick.Event("right_x"), func(data interface{}) { val := float64(data.(int16)) if rightStick.x != val { rightStick.x = val } }) gobot.On(joystick.Event("right_y"), func(data interface{}) { val := float64(data.(int16)) if rightStick.y != val { rightStick.y = val } }) gobot.Every(10*time.Millisecond, func() { pair := leftStick if pair.y < -10 { drone.Forward(validatePitch(pair.y, offset)) } else if pair.y > 10 { drone.Backward(validatePitch(pair.y, offset)) } else { drone.Forward(0) } if pair.x > 10 { drone.Right(validatePitch(pair.x, offset)) } else if pair.x < -10 { drone.Left(validatePitch(pair.x, offset)) } else { drone.Right(0) } }) gobot.Every(10*time.Millisecond, func() { pair := rightStick if pair.y < -10 { drone.Up(validatePitch(pair.y, offset)) } else if pair.y > 10 { drone.Down(validatePitch(pair.y, offset)) } else { drone.Up(0) } if pair.x > 20 { drone.Clockwise(validatePitch(pair.x, offset)) } else if pair.x < -20 { drone.CounterClockwise(validatePitch(pair.x, offset)) } else { drone.Clockwise(0) } }) } robot := gobot.NewRobot("ardrone", []gobot.Connection{joystickAdaptor, ardroneAdaptor, m}, []gobot.Device{joystick, drone}, work, ) gbot.AddRobot(robot) gbot.Start() }
func main() { gbot := gobot.NewGobot() joystickAdaptor := joystick.NewJoystickAdaptor("ps3") joystick := joystick.NewJoystickDriver(joystickAdaptor, "ps3", "./platforms/joystick/configs/dualshock3.json", ) bebopAdaptor := bebop.NewBebopAdaptor("Drone") drone := bebop.NewBebopDriver(bebopAdaptor, "Drone") work := func() { offset := 32767.0 rightStick := pair{x: 0, y: 0} leftStick := pair{x: 0, y: 0} recording := false gobot.On(joystick.Event("circle_press"), func(data interface{}) { if recording { drone.StopRecording() } else { drone.StartRecording() } recording = !recording }) gobot.On(joystick.Event("square_press"), func(data interface{}) { drone.HullProtection(true) drone.TakeOff() }) gobot.On(joystick.Event("triangle_press"), func(data interface{}) { drone.Stop() }) gobot.On(joystick.Event("x_press"), func(data interface{}) { drone.Land() }) gobot.On(joystick.Event("left_x"), func(data interface{}) { val := float64(data.(int16)) if leftStick.x != val { leftStick.x = val } }) gobot.On(joystick.Event("left_y"), func(data interface{}) { val := float64(data.(int16)) if leftStick.y != val { leftStick.y = val } }) gobot.On(joystick.Event("right_x"), func(data interface{}) { val := float64(data.(int16)) if rightStick.x != val { rightStick.x = val } }) gobot.On(joystick.Event("right_y"), func(data interface{}) { val := float64(data.(int16)) if rightStick.y != val { rightStick.y = val } }) gobot.Every(10*time.Millisecond, func() { pair := leftStick if pair.y < -10 { drone.Forward(validatePitch(pair.y, offset)) } else if pair.y > 10 { drone.Backward(validatePitch(pair.y, offset)) } else { drone.Forward(0) } if pair.x > 10 { drone.Right(validatePitch(pair.x, offset)) } else if pair.x < -10 { drone.Left(validatePitch(pair.x, offset)) } else { drone.Right(0) } }) gobot.Every(10*time.Millisecond, func() { pair := rightStick if pair.y < -10 { drone.Up(validatePitch(pair.y, offset)) } else if pair.y > 10 { drone.Down(validatePitch(pair.y, offset)) } else { drone.Up(0) } if pair.x > 20 { drone.Clockwise(validatePitch(pair.x, offset)) } else if pair.x < -20 { drone.CounterClockwise(validatePitch(pair.x, offset)) } else { drone.Clockwise(0) } }) } robot := gobot.NewRobot("bebop", []gobot.Connection{joystickAdaptor, bebopAdaptor}, []gobot.Device{joystick, drone}, work, ) gbot.AddRobot(robot) gbot.Start() }
func main() { pwd, _ := os.Getwd() joystickConfig := pwd + "/dualshock3.json" gbot := gobot.NewGobot() joystickAdaptor := joystick.NewJoystickAdaptor("ps3") joystick := joystick.NewJoystickDriver(joystickAdaptor, "ps3", joystickConfig, ) droneAdaptor := ble.NewBLEAdaptor("ble", os.Args[1]) drone := ble.NewBLEMinidroneDriver(droneAdaptor, "drone") work := func() { offset := 32767.0 rightStick := pair{x: 0, y: 0} leftStick := pair{x: 0, y: 0} gobot.On(joystick.Event("triangle_press"), func(data interface{}) { drone.TakeOff() }) gobot.On(joystick.Event("square_press"), func(data interface{}) { drone.Stop() }) gobot.On(joystick.Event("x_press"), func(data interface{}) { drone.Land() }) gobot.On(joystick.Event("left_x"), func(data interface{}) { val := float64(data.(int16)) if leftStick.x != val { leftStick.x = val } }) gobot.On(joystick.Event("left_y"), func(data interface{}) { val := float64(data.(int16)) if leftStick.y != val { leftStick.y = val } }) gobot.On(joystick.Event("right_x"), func(data interface{}) { val := float64(data.(int16)) if rightStick.x != val { rightStick.x = val } }) gobot.On(joystick.Event("right_y"), func(data interface{}) { val := float64(data.(int16)) if rightStick.y != val { rightStick.y = val } }) gobot.Every(10*time.Millisecond, func() { pair := rightStick if pair.y < -10 { drone.Forward(validatePitch(pair.y, offset)) } else if pair.y > 10 { drone.Backward(validatePitch(pair.y, offset)) } else { drone.Forward(0) } if pair.x > 10 { drone.Right(validatePitch(pair.x, offset)) } else if pair.x < -10 { drone.Left(validatePitch(pair.x, offset)) } else { drone.Right(0) } }) gobot.Every(10*time.Millisecond, func() { pair := leftStick if pair.y < -10 { drone.Up(validatePitch(pair.y, offset)) } else if pair.y > 10 { drone.Down(validatePitch(pair.y, offset)) } else { drone.Up(0) } if pair.x > 20 { drone.Clockwise(validatePitch(pair.x, offset)) } else if pair.x < -20 { drone.CounterClockwise(validatePitch(pair.x, offset)) } else { drone.Clockwise(0) } }) } robot := gobot.NewRobot("minidrone", []gobot.Connection{joystickAdaptor, droneAdaptor}, []gobot.Device{joystick, drone}, work, ) gbot.AddRobot(robot) gbot.Start() }