duanhuanyou6478 2018-12-11 22:58
浏览 6

使用gobot库使Sphero的BB8绕圈走会导致错误消息

I have recently discovered the awesome gobot library which also interfaces with Sphero's BB8. I am trying to make the robot go in a circle, and while the BB8 behaves as expected, I get error messages in the console.

Here's the function I am using to make the BB8 go in a circle:

func circles(driver *bb8.BB8Driver, steps float64) {
    rotateBy := math.Floor(360.0 / steps)
    currentAngle := 5.0
    directionInterval := 300

    for i := 0; i < int(steps); i++ {
        gobot.After(time.Millisecond*time.Duration(directionInterval), func() {
            driver.Roll(80, uint16(int(currentAngle)%360))
            currentAngle+=rotateBy
            directionInterval+=directionInterval
        })
    }
    gobot.After(time.Millisecond*time.Duration(directionInterval+500), func() {
        driver.Halt()
    })
}

And this is the worker program:

package main

import (
    "math"
    "os"

    "gobot.io/x/gobot"
    "gobot.io/x/gobot/platforms/ble"
    "gobot.io/x/gobot/platforms/sphero/bb8"
)

func main() {
    bleAdaptor := ble.NewClientAdaptor(os.Args[1])
    bb := bb8.NewDriver(bleAdaptor)
    work := func() {
        circles2(bb, 50)
    }

    robot := gobot.NewRobot("bb",
        []gobot.Connection{bleAdaptor},
        []gobot.Device{bb},
        work,
    )

    robot.Start()
}

When I run this, the robot does what I want it to do. However, I repeatedly get the same error message in the console suggesting the for loop is overloading a messaging queue of sorts:

ERR att client req: can't enqueue incoming notification. goroutine 34 [running]: runtime/debug.Stack(0x0, 0x0, 0x0) /usr/lib/go-1.7/src/runtime/debug/stack.go:24 +0x84 github.com/mgutz/logxi/v1.(*HappyDevFormatter).getLevelContext(0x1056a7e0, 0x3, 0x106418a0, 0x0, 0x0, 0x0, 0x0, 0x1056a794, 0x5) /path/to/dir/bb8/src/github.com/go-ble/ble/linux/att/client.go:551 +0x930 created by github.com/go-ble/ble/linux/gatt.NewClient /path/to/dir/bb8/src/github.com/go-ble/ble/linux/gatt/client.go:25 +0x124

I am wondering whether there is a better approach that avoids the error messages, as my knowledge of Go is still fairly limited. Any suggestions and comments are appreciated!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 R语言Rstudio突然无法启动
    • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
    • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
    • ¥15 用windows做服务的同志有吗
    • ¥60 求一个简单的网页(标签-安全|关键词-上传)
    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值