本文整理汇总了Golang中github.com/hybridgroup/gobot.Robot类的典型用法代码示例。如果您正苦于以下问题:Golang Robot类的具体用法?Golang Robot怎么用?Golang Robot使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Robot类的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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()
}
开发者ID:ninetwentyfour,项目名称:gobot-beaglebone,代码行数:30,代码来源:led_brightness_with_analog_input.go
示例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()
}
开发者ID:ninetwentyfour,项目名称:gobot-beaglebone,代码行数:29,代码来源:led_brightness.go
示例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()
}
开发者ID:ninetwentyfour,项目名称:gobot-beaglebone,代码行数:25,代码来源:blinkm.go
示例4: main
func main() {
robot := gobot.Robot{
Work: func() {
gobot.Every("0.5s", func() { fmt.Println("Greetings human") })
},
}
robot.Start()
}
开发者ID:nordicdyno,项目名称:gobot,代码行数:9,代码来源:hello.go
示例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()
}
开发者ID:romtastic,项目名称:gobot,代码行数:12,代码来源:hello_api.go
示例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()
}
开发者ID:nabeshi,项目名称:gundam,代码行数:14,代码来源:sphero.go
示例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()
}
开发者ID:nordicdyno,项目名称:gobot,代码行数:14,代码来源:hello_api_auth.go
示例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()
}
开发者ID:jeromenerf,项目名称:gobots,代码行数:49,代码来源:joysphero.go
示例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()
}
开发者ID:jergason,项目名称:gobot-sphero,代码行数:48,代码来源:sphero.go
示例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()
}
开发者ID:roca,项目名称:GO,代码行数:20,代码来源:led_demo.go
示例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()
}
开发者ID:jeromenerf,项目名称:gobots,代码行数:22,代码来源:leap.go
示例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()
}
开发者ID:jeromenerf,项目名称:gobots,代码行数:38,代码来源:joystick.go
示例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()
}
开发者ID:nordicdyno,项目名称:gobot,代码行数:23,代码来源:sphero.go
示例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
}
开发者ID:Remote-Oculus-Controller,项目名称:R.O.C-CONTROLS,代码行数:9,代码来源:motion.go
示例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()
}
开发者ID:ninetwentyfour,项目名称:gobot-beaglebone,代码行数:24,代码来源:servo.go
示例16: main
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()
}
开发者ID:jhotta,项目名称:project-x,代码行数:24,代码来源:blink.go
示例17: main
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},
//.........这里部分代码省略.........
开发者ID:jeromenerf,项目名称:gobots,代码行数:101,代码来源:ardrone.go
示例18: resetLeds
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()
}
开发者ID:ninetwentyfour,项目名称:gobot,代码行数:5,代码来源:firmata_travis.go
示例19: turnOn
func turnOn(robot *gobot.Robot, device string) {
robot.Device(device).Driver.(*gpio.LedDriver).On()
}
开发者ID:ninetwentyfour,项目名称:gobot,代码行数:3,代码来源:firmata_travis.go
注:本文中的github.com/hybridgroup/gobot.Robot类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论