func main() {
	beaglebone := new(gobotBeaglebone.Beaglebone)
	beaglebone.Name = "beaglebone"

	sensor := gobotGPIO.NewAnalogSensor(beaglebone)
	sensor.Name = "sensor"
	sensor.Pin = "P9_33"

	led := gobotGPIO.NewLed(beaglebone)
	led.Name = "led"
	led.Pin = "P9_14"

	work := func() {
		gobot.Every("0.1s", func() {
			val := sensor.Read()
			brightness := uint8(gobotGPIO.ToPwm(val))
			fmt.Println("sensor", val)
			fmt.Println("brightness", brightness)
			led.Brightness(brightness)
		})
	}

	robot := gobot.Robot{
		Connections: []gobot.Connection{beaglebone},
		Devices:     []gobot.Device{sensor, led},
		Work:        work,
	}

	robot.Start()
}
func main() {
	beaglebone := new(gobotBeaglebone.Beaglebone)
	beaglebone.Name = "beaglebone"

	led := gobotGPIO.NewLed(beaglebone)
	led.Name = "led"
	led.Pin = "P9_14"

	work := func() {
		brightness := uint8(0)
		fade_amount := uint8(5)

		gobot.Every("0.1s", func() {
			led.Brightness(brightness)
			brightness = brightness + fade_amount
			if brightness == 0 || brightness == 255 {
				fade_amount = -fade_amount
			}
		})
	}

	robot := gobot.Robot{
		Connections: []gobot.Connection{beaglebone},
		Devices:     []gobot.Device{led},
		Work:        work,
	}

	robot.Start()
}
func main() {
	beaglebone := new(gobotBeaglebone.Beaglebone)
	beaglebone.Name = "beaglebone"

	blinkm := gobotI2C.NewBlinkM(beaglebone)
	blinkm.Name = "blinkm"

	work := func() {
		gobot.Every("3s", func() {
			r := byte(gobot.Rand(255))
			g := byte(gobot.Rand(255))
			b := byte(gobot.Rand(255))
			blinkm.Rgb(r, g, b)
			fmt.Println("color", blinkm.Color())
		})
	}

	robot := gobot.Robot{
		Connections: []gobot.Connection{beaglebone},
		Devices:     []gobot.Device{blinkm},
		Work:        work,
	}

	robot.Start()
}
Example #4
0
func main() {
	robot := gobot.Robot{
		Work: func() {
			gobot.Every("0.5s", func() { fmt.Println("Greetings human") })
		},
	}

	robot.Start()
}
Example #5
0
func main() {
	master := gobot.GobotMaster()
	gobot.Api(master)

	hello := new(gobot.Robot)
	hello.Name = "hello"
	hello.Commands = map[string]interface{}{"Hello": Hello}

	master.Robots = append(master.Robots, *hello)

	master.Start()
}
Example #6
0
func (s *sphero) Start() {
	s.connection = new(gobotSphero.SpheroAdaptor)
	s.connection.Name = "sphero"
	s.connection.Port = s.Port

	s.device = gobotSphero.NewSphero(s.connection)
	s.device.Name = s.Name

	robot := gobot.Robot{
		Connections: []gobot.Connection{s.connection},
		Devices:     []gobot.Device{s.device},
	}
	robot.Start()
}
Example #7
0
func main() {
	master := gobot.GobotMaster()
	api := gobot.Api(master)
	api.Username = "******"
	api.Password = "******"

	hello := new(gobot.Robot)
	hello.Name = "hello"
	hello.Commands = map[string]interface{}{"Hello": Hello}

	master.Robots = append(master.Robots, hello)

	master.Start()
}
Example #8
0
func main() {
	joystickAdaptor := new(gobotJoystick.JoystickAdaptor)
	joystickAdaptor.Name = "x52"
	joystickAdaptor.Params = map[string]interface{}{
		"config": "./saitek-x52.json",
	}

	joystick := gobotJoystick.NewJoystick(joystickAdaptor)
	joystick.Name = "x52"

	spheroAdaptor := new(gobotSphero.SpheroAdaptor)
	spheroAdaptor.Name = "Sphero"
	spheroAdaptor.Port = "/dev/tty.Sphero-PWG-RN-SPP"

	sphero := gobotSphero.NewSphero(spheroAdaptor)
	sphero.Name = "Sphero"
	var (
		x, y      int
		direction uint16
		speed     uint8
	)
	x = 1
	y = 1
	direction = 0
	speed = 0

	work := func() {
		gobot.On(joystick.Events["right_x"], func(data interface{}) {
			x = int(data.(int16))
		})
		gobot.On(joystick.Events["right_y"], func(data interface{}) {
			y = int(data.(int16))
		})
		gobot.Every("0.01s", func() {
			direction = Angle(x, y)
			speed = uint8(math.Sqrt(float64(x*x+y*y)) / 128) //255
			fmt.Println(x, y, speed, direction)
			sphero.Roll(speed, direction)
		})
	}

	robot := gobot.Robot{
		Connections: []gobot.Connection{joystickAdaptor, spheroAdaptor},
		Devices:     []gobot.Device{joystick, sphero},
		Work:        work,
	}

	robot.Start()
}
Example #9
0
func main() {

	spheroAdaptor := new(gobotSphero.SpheroAdaptor)
	spheroAdaptor.Name = "Sphero"
	spheroAdaptor.Port = "127.0.0.1:4560"

	sphero := gobotSphero.NewSphero(spheroAdaptor)
	sphero.Name = "Sphero"

	connections := []interface{}{
		spheroAdaptor,
	}
	devices := []interface{}{
		sphero,
	}

	work := func() {

		sphero.Stop()

		go func() {
			for {
				gobot.On(sphero.Events["Collision"])
				fmt.Println("Collision Detected!")
			}
		}()

		gobot.Every("2s", func() {
			dir := uint16(gobot.Random(0, 360))
			sphero.Roll(100, dir)
		})

		gobot.Every("3s", func() {
			r := uint8(gobot.Random(0, 255))
			g := uint8(gobot.Random(0, 255))
			b := uint8(gobot.Random(0, 255))
			sphero.SetRGB(r, g, b)
		})
	}

	robot := gobot.Robot{
		Connections: connections,
		Devices:     devices,
		Work:        work,
	}

	robot.Start()
}
Example #10
0
File: led_demo.go Project: roca/GO
func main() {
	beaglebone := new(gobotBeaglebone.Beaglebone)
	beaglebone.Name = "beaglebone"

	led := gobotGPIO.NewLed(beaglebone)
	led.Name = "led"
	led.Pin = "P8_10"

	work := func() {
		gobot.Every("1s", func() { led.Toggle() })
	}

	robot := gobot.Robot{
		Connections: []gobot.Connection{beaglebone},
		Devices:     []gobot.Device{led},
		Work:        work,
	}

	robot.Start()
}
Example #11
0
func main() {
	leapAdaptor := new(gobotLeap.LeapAdaptor)
	leapAdaptor.Name = "leap"
	leapAdaptor.Port = "127.0.0.1:6437"

	leap := gobotLeap.NewLeap(leapAdaptor)
	leap.Name = "leap"

	work := func() {
		gobot.On(leap.Events["Message"], func(data interface{}) {
			printGestures(data.(gobotLeap.LeapFrame))
		})
	}

	robot := gobot.Robot{
		Connections: []gobot.Connection{leapAdaptor},
		Devices:     []gobot.Device{leap},
		Work:        work,
	}

	robot.Start()
}
Example #12
0
func main() {
	joystickAdaptor := new(gobotJoystick.JoystickAdaptor)
	joystickAdaptor.Name = "x52"
	joystickAdaptor.Params = map[string]interface{}{
		"config": "./saitek-x52-reverse.json",
	}

	joystick := gobotJoystick.NewJoystick(joystickAdaptor)
	joystick.Name = "x52"
	offset := 32767.0

	work := func() {
		gobot.On(joystick.Events["left_throttle"], func(data interface{}) {
			val := float64(data.(int16))
			fmt.Println("left_throttle", validatePitch(val, offset), val)
		})
		gobot.On(joystick.Events["right_rotate"], func(data interface{}) {
			val := float64(data.(int16))
			fmt.Println("right_rotate", validatePitch(val, offset), val)
		})
		gobot.On(joystick.Events["right_x"], func(data interface{}) {
			val := float64(data.(int16))
			fmt.Println("right_x", validatePitch(val, offset), val)
		})
		gobot.On(joystick.Events["right_y"], func(data interface{}) {
			val := float64(data.(int16))
			fmt.Println("right_y", validatePitch(val, offset), val)
		})
	}

	robot := gobot.Robot{
		Connections: []gobot.Connection{joystickAdaptor},
		Devices:     []gobot.Device{joystick},
		Work:        work,
	}

	robot.Start()
}
Example #13
0
func main() {

	spheroAdaptor := new(gobotSphero.SpheroAdaptor)
	spheroAdaptor.Name = "Sphero"
	spheroAdaptor.Port = "/dev/rfcomm0"

	sphero := gobotSphero.NewSphero(spheroAdaptor)
	sphero.Name = "Sphero"

	work := func() {
		gobot.Every("2s", func() {
			sphero.Roll(100, uint16(gobot.Rand(360)))
		})
	}

	robot := gobot.Robot{
		Connections: []gobot.Connection{spheroAdaptor},
		Devices:     []gobot.Device{sphero},
		Work:        work,
	}

	robot.Start()
}
func (m *Motion) Equal(r *gobot.Robot) {

	m.arduino = r.Connection("arduino").(*firmata.FirmataAdaptor)
	m.servoY = r.Device("servoY").(*gpio.ServoDriver)
	m.servoX = r.Device("servoX").(*gpio.ServoDriver)
	m.motorL = r.Device("motorL").(*gpio.ServoDriver)
	m.motorR = r.Device("motorR").(*gpio.ServoDriver)
	m.Robot.Robot = r
}
Example #15
0
func main() {
	beaglebone := new(gobotBeaglebone.Beaglebone)
	beaglebone.Name = "beaglebone"

	servo := gobotGPIO.NewServo(beaglebone)
	servo.Name = "servo"
	servo.Pin = "P9_14"

	work := func() {
		gobot.Every("1s", func() {
			i := uint8(gobot.Rand(180))
			fmt.Println("Turning", i)
			servo.Move(i)
		})
	}

	robot := gobot.Robot{
		Connections: []gobot.Connection{beaglebone},
		Devices:     []gobot.Device{servo},
		Work:        work,
	}

	robot.Start()
}
Example #16
0
func main() {

	firmata := new(gobotFirmata.FirmataAdaptor)
	firmata.Name = "firmata"
	firmata.Port = "/dev/ttyACM0"

	led := gobotGPIO.NewLed(firmata)
	led.Name = "led"
	led.Pin = "5"

	work := func() {
		gobot.Every("500ms", func() {
			led.Toggle()
		})
	}

	robot := gobot.Robot{
		Connections: []gobot.Connection{firmata},
		Devices:     []gobot.Device{led},
		Work:        work,
	}

	robot.Start()
}
Example #17
0
func main() {
	joystickAdaptor := new(gobotJoystick.JoystickAdaptor)
	joystickAdaptor.Name = "saitek"
	joystickAdaptor.Params = map[string]interface{}{
		"config": "./saitek-x52-reverse.json",
	}

	joystick := gobotJoystick.NewJoystick(joystickAdaptor)
	joystick.Name = "saitek"

	ardroneAdaptor := new(gobotArdrone.ArdroneAdaptor)
	ardroneAdaptor.Name = "Drone"

	drone := gobotArdrone.NewArdrone(ardroneAdaptor)
	drone.Name = "Drone"

	work := func() {

		offset := 32767.0
		right_stick := pair{x: 0, y: 0}
		left_stick := pair{x: 0, y: 0}

		gobot.On(joystick.Events["T1_press"], func(data interface{}) {
			drone.TakeOff()
		})
		gobot.On(joystick.Events["T3_press"], func(data interface{}) {
			drone.Hover()
		})
		gobot.On(joystick.Events["A_press"], func(data interface{}) {
			drone.Land()
		})
		gobot.On(joystick.Events["B_press"], func(data interface{}) {
			drone.Halt()
		})
		gobot.On(joystick.Events["right_x"], func(data interface{}) {
			val := float64(data.(int16))
			if left_stick.x-val < 500 {
				left_stick.x = val
			}
		})
		gobot.On(joystick.Events["right_y"], func(data interface{}) {
			val := float64(data.(int16))
			if left_stick.y-val < 500 {
				left_stick.y = val
			}
		})
		gobot.On(joystick.Events["right_rotate"], func(data interface{}) {
			val := float64(data.(int16))
			if right_stick.x-val < 500 {
				right_stick.x = val
			}
		})
		gobot.On(joystick.Events["left_throttle"], func(data interface{}) {
			val := float64(data.(int16))
			if right_stick.y-val < 100 {
				right_stick.y = val
			}
		})

		gobot.Every("0.01s", func() {
			pair := left_stick
			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("0.01s", func() {
			pair := right_stick
			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 > 10 {
				drone.Clockwise(validatePitch(pair.x, offset))
			} else if pair.x < -10 {
				drone.CounterClockwise(validatePitch(pair.x, offset))
			} else {
				drone.Clockwise(0)
			}
		})
	}

	robot := gobot.Robot{
		Connections: []gobot.Connection{joystickAdaptor, ardroneAdaptor},
		Devices:     []gobot.Device{joystick, drone},
		Work:        work,
	}

	robot.Start()
}
Example #18
0
func resetLeds(robot *gobot.Robot) {
	robot.Device("red").Driver.(*gpio.LedDriver).Off()
	robot.Device("green").Driver.(*gpio.LedDriver).Off()
	robot.Device("blue").Driver.(*gpio.LedDriver).Off()
}
Example #19
0
func turnOn(robot *gobot.Robot, device string) {
	robot.Device(device).Driver.(*gpio.LedDriver).On()
}