本文整理汇总了Golang中github.com/hybridgroup/gobot.Robot类的典型用法代码示例。如果您正苦于以下问题:Golang Robot类的具体用法?Golang Robot怎么用?Golang Robot使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Robot类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
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()
}
示例2: main
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()
}
示例3: main
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()
}
示例4: main
func main() {
robot := gobot.Robot{
Work: func() {
gobot.Every("0.5s", func() { fmt.Println("Greetings human") })
},
}
robot.Start()
}
示例5: main
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()
}
示例6: Start
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()
}
示例7: main
func main() {
master := gobot.GobotMaster()
api := gobot.Api(master)
api.Username = "gort"
api.Password = "klatuu"
hello := new(gobot.Robot)
hello.Name = "hello"
hello.Commands = map[string]interface{}{"Hello": Hello}
master.Robots = append(master.Robots, hello)
master.Start()
}
示例8: main
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()
}
示例9: main
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()
}
示例10: main
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()
}
示例11: main
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()
}
示例12: main
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()
}
示例13: main
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()
}
示例14: Equal
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
}
示例15: main
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()
}