func main() { gbot := gobot.NewGobot() joystickAdaptor := joystick.NewJoystickAdaptor("ps4") joystick := joystick.NewJoystickDriver(joystickAdaptor, "ps4", "./platforms/joystick/configs/dualshock4.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("circle_press"), func(data interface{}) { fmt.Println("circle_press") }) gobot.On(joystick.Event("circle_release"), func(data interface{}) { fmt.Println("circle_release") }) gobot.On(joystick.Event("x_press"), func(data interface{}) { fmt.Println("x_press") }) gobot.On(joystick.Event("x_release"), func(data interface{}) { fmt.Println("x_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") stick := joystick.NewJoystickDriver(joystickAdaptor, "xbox360", "./platforms/joystick/configs/joystick/configs/xbox360_power_a_mini_proex.json", ) work := func() { stick.On(joystick.APress, func(data interface{}) { fmt.Println("a_press") }) stick.On(joystick.ARelease, func(data interface{}) { fmt.Println("a_release") }) stick.On(joystick.BPress, func(data interface{}) { fmt.Println("b_press") }) stick.On(joystick.BRelease, func(data interface{}) { fmt.Println("b_release") }) stick.On(joystick.Up, func(data interface{}) { fmt.Println("up", data) }) stick.On(joystick.Down, func(data interface{}) { fmt.Println("down", data) }) stick.On(joystick.Left, func(data interface{}) { fmt.Println("left", data) }) stick.On(joystick.Right, func(data interface{}) { fmt.Println("right", data) }) stick.On(joystick.LeftX, func(data interface{}) { fmt.Println("left_x", data) }) stick.On(joystick.LeftY, func(data interface{}) { fmt.Println("left_y", data) }) stick.On(joystick.RightX, func(data interface{}) { fmt.Println("right_x", data) }) stick.On(joystick.RightY, func(data interface{}) { fmt.Println("right_y", data) }) } robot := gobot.NewRobot("joystickBot", []gobot.Connection{joystickAdaptor}, []gobot.Device{stick}, work, ) gbot.AddRobot(robot) gbot.Start() }
func main() { gbot := gobot.NewGobot() joystickAdaptor := joystick.NewJoystickAdaptor("xbox360") joystickDriver := joystick.NewJoystickDriver(joystickAdaptor, "xbox360", "./platforms/joystick/configs/joystick/configs/xbox360_power_a_mini_proex.json") work := func() { gobot.On(joystickDriver.Events["a_press"], func(data interface{}) { fmt.Println("a_press") }) gobot.On(joystickDriver.Events["a_release"], func(data interface{}) { fmt.Println("a_release") }) gobot.On(joystickDriver.Events["b_press"], func(data interface{}) { fmt.Println("b_press") }) gobot.On(joystickDriver.Events["b_release"], func(data interface{}) { fmt.Println("b_release") }) gobot.On(joystickDriver.Events["up"], func(data interface{}) { fmt.Println("up", data) }) gobot.On(joystickDriver.Events["down"], func(data interface{}) { fmt.Println("down", data) }) gobot.On(joystickDriver.Events["left"], func(data interface{}) { fmt.Println("left", data) }) gobot.On(joystickDriver.Events["right"], func(data interface{}) { fmt.Println("right", data) }) gobot.On(joystickDriver.Events["left_x"], func(data interface{}) { fmt.Println("left_x", data) }) gobot.On(joystickDriver.Events["left_y"], func(data interface{}) { fmt.Println("left_y", data) }) gobot.On(joystickDriver.Events["right_x"], func(data interface{}) { fmt.Println("right_x", data) }) gobot.On(joystickDriver.Events["right_y"], func(data interface{}) { fmt.Println("right_y", data) }) } gbot.Robots = append(gbot.Robots, gobot.NewRobot("joystickBot", []gobot.Connection{joystickAdaptor}, []gobot.Device{joystickDriver}, work)) gbot.Start() }
func main() { gbot := gobot.NewGobot() joystickAdaptor := joystick.NewJoystickAdaptor("ps3") stick := joystick.NewJoystickDriver(joystickAdaptor, "ps3", "./platforms/joystick/configs/dualshock3.json", ) work := func() { stick.On(joystick.SquarePress, func(data interface{}) { fmt.Println("square_press") }) stick.On(joystick.SquareRelease, func(data interface{}) { fmt.Println("square_release") }) stick.On(joystick.TrianglePress, func(data interface{}) { fmt.Println("triangle_press") }) stick.On(joystick.TriangleRelease, func(data interface{}) { fmt.Println("triangle_release") }) stick.On(joystick.LeftX, func(data interface{}) { fmt.Println("left_x", data) }) stick.On(joystick.LeftY, func(data interface{}) { fmt.Println("left_y", data) }) stick.On(joystick.RightX, func(data interface{}) { fmt.Println("right_x", data) }) stick.On(joystick.RightY, func(data interface{}) { fmt.Println("right_y", data) }) } robot := gobot.NewRobot("joystickBot", []gobot.Connection{joystickAdaptor}, []gobot.Device{stick}, work, ) gbot.AddRobot(robot) gbot.Start() }
func main() { gbot := gobot.NewGobot() joystickAdaptor := joystick.NewJoystickAdaptor("ps3") joystickDriver := joystick.NewJoystickDriver(joystickAdaptor, "ps3", "./platforms/joystick/configs/dualshock3.json") work := func() { gobot.On(joystickDriver.Events["square_press"], func(data interface{}) { fmt.Println("square_press") }) gobot.On(joystickDriver.Events["square_release"], func(data interface{}) { fmt.Println("square_release") }) gobot.On(joystickDriver.Events["triangle_press"], func(data interface{}) { fmt.Println("triangle_press") }) gobot.On(joystickDriver.Events["triangle_release"], func(data interface{}) { fmt.Println("triangle_release") }) gobot.On(joystickDriver.Events["left_x"], func(data interface{}) { fmt.Println("left_x", data) }) gobot.On(joystickDriver.Events["left_y"], func(data interface{}) { fmt.Println("left_y", data) }) gobot.On(joystickDriver.Events["right_x"], func(data interface{}) { fmt.Println("right_x", data) }) gobot.On(joystickDriver.Events["right_y"], func(data interface{}) { fmt.Println("right_y", data) }) } gbot.Robots = append(gbot.Robots, gobot.NewRobot("joystickBot", []gobot.Connection{joystickAdaptor}, []gobot.Device{joystickDriver}, work)) gbot.Start() }
func main() { gbot := gobot.NewGobot() joystickAdaptor := joystick.NewJoystickAdaptor("ps3") stick := joystick.NewJoystickDriver(joystickAdaptor, "ps3", "./platforms/joystick/configs/dualshock3.json", ) bebopAdaptor := bebop.NewBebopAdaptor("Drone") drone := bebop.NewBebopDriver(bebopAdaptor, "Drone") work := func() { video, _, _ := ffmpeg() go func() { for { if _, err := video.Write(<-drone.Video()); err != nil { fmt.Println(err) return } } }() offset := 32767.0 rightStick := pair{x: 0, y: 0} leftStick := pair{x: 0, y: 0} recording := false stick.On(joystick.CirclePress, func(data interface{}) { if recording { drone.StopRecording() } else { drone.StartRecording() } recording = !recording }) stick.On(joystick.SquarePress, func(data interface{}) { drone.HullProtection(true) drone.TakeOff() }) stick.On(joystick.TrianglePress, func(data interface{}) { drone.Stop() }) stick.On(joystick.XPress, func(data interface{}) { drone.Land() }) stick.On(joystick.LeftX, func(data interface{}) { val := float64(data.(int16)) if leftStick.x != val { leftStick.x = val } }) stick.On(joystick.LeftY, func(data interface{}) { val := float64(data.(int16)) if leftStick.y != val { leftStick.y = val } }) stick.On(joystick.RightX, func(data interface{}) { val := float64(data.(int16)) if rightStick.x != val { rightStick.x = val } }) stick.On(joystick.RightY, 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{stick, 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") ardroneAdaptor := ardrone.NewArdroneAdaptor("Drone") drone := ardrone.NewArdroneDriver(ardroneAdaptor, "Drone") work := func() { offset := 32767.0 rightStick := pair{x: 0, y: 0} leftStick := pair{x: 0, y: 0} gobot.On(joystick.Events["square_press"], func(data interface{}) { drone.TakeOff() }) gobot.On(joystick.Events["triangle_press"], func(data interface{}) { drone.Hover() }) gobot.On(joystick.Events["x_press"], func(data interface{}) { drone.Land() }) gobot.On(joystick.Events["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{}) { val := float64(data.(int16)) if leftStick.y != val { leftStick.y = val } }) gobot.On(joystick.Events["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{}) { 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) } }) } gbot.Robots = append(gbot.Robots, gobot.NewRobot("ardrone", []gobot.Connection{joystickAdaptor, ardroneAdaptor}, []gobot.Device{joystick, drone}, work)) 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() }
func main() { gbot := gobot.NewGobot() joystickAdaptor := joystick.NewJoystickAdaptor("ps3") stick := joystick.NewJoystickDriver(joystickAdaptor, "ps3", "./platforms/joystick/configs/dualshock3.json", ) droneAdaptor := ble.NewBLEClientAdaptor("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} recording := false stick.On(joystick.CirclePress, func(data interface{}) { if recording { drone.StopRecording() } else { drone.StartRecording() } recording = !recording }) stick.On(joystick.SquarePress, func(data interface{}) { drone.HullProtection(true) drone.TakeOff() }) stick.On(joystick.TrianglePress, func(data interface{}) { drone.Stop() }) stick.On(joystick.XPress, func(data interface{}) { drone.Land() }) stick.On(joystick.LeftX, func(data interface{}) { val := float64(data.(int16)) if leftStick.x != val { leftStick.x = val } }) stick.On(joystick.LeftY, func(data interface{}) { val := float64(data.(int16)) if leftStick.y != val { leftStick.y = val } }) stick.On(joystick.RightX, func(data interface{}) { val := float64(data.(int16)) if rightStick.x != val { rightStick.x = val } }) stick.On(joystick.RightY, 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("minidrone", []gobot.Connection{joystickAdaptor, droneAdaptor}, []gobot.Device{stick, drone}, work, ) gbot.AddRobot(robot) gbot.Start() }