Closed tangsoft closed 10 years ago
@tangsoft thank's for reporting the issue, I'll look into it
@tangsoft I created this branch with a hotfix https://github.com/hybridgroup/gobot/tree/sphero_hotfix. Can you pull the code a test that it works for you?
Sometimes the sphero takes too long to respond, or the packet it sends back is incomplete. If that is the case I will now return an empty array, but if the packet is well formed you will get an array with the three RGB values.
Here's the output from my local test
2014/07/25 09:12:18 Initializing Robot sphero ...
2014/07/25 09:12:18 Initializing connections...
2014/07/25 09:12:18 Initializing connection Sphero ...
2014/07/25 09:12:18 Initializing devices...
2014/07/25 09:12:18 Initializing device sphero ...
2014/07/25 09:12:18 Starting Robot sphero ...
2014/07/25 09:12:18 Starting connections...
2014/07/25 09:12:18 Starting connection Sphero on port /dev/rfcomm0...
2014/07/25 09:12:18 Starting devices...
2014/07/25 09:12:18 Starting device sphero...
2014/07/25 09:12:18 Starting work...
spheroDriver.SetRGB(153, 61, 202)
spheroDriver.GetRGB() [153 61 202]
spheroDriver.SetRGB(45, 18, 187)
spheroDriver.GetRGB() [45 18 187]
spheroDriver.SetRGB(103, 214, 72)
spheroDriver.GetRGB() [103 214 72]
spheroDriver.SetRGB(215, 63, 139)
@zankich thanks, it works now. additionally, i have to wait about half a second before sending a request to sphero like this, especially when you want send several requests sequentially: time.Sleep(500 * time.Millisecond)
by the way, is there any plan you guys will implement a full set of sphero API 1.5? at the same time, i have a suggestion, since there are more than one DID, shall we have one more parameter pass to craftPacket func? for example when I want to get power state, i have to send request virtual device 0x00, not 0x02.
func (s *SpheroDriver) GetPowerState() []uint8 { 189 return s.getSyncResponse(s.craftPacket([]uint8{}, 0x00, 0x20)) 190 }
func (s SpheroDriver) craftPacket(body []uint8, did byte, cid byte) packet { 249 packet := new(packet) 250 packet.body = body 251 dlen := len(packet.body) + 1 252 packet.header = []uint8{0xFF, 0xFF, did, cid, s.seq, uint8(dlen)} 253 packet.checksum = s.calculateChecksum(packet) 254 return packet
2014/07/26 10:46:10 Starting work... ChassisID is [255 255 0 1 3 0 4 247] Current DeviceMode is [255 255 0 2 2 1 250] Versioning is [255 255 0 3 9 1 3 1 3 59 51 23 6 96] PowerState is [255 255 0 4 9 1 2 3 33 0 43 6 63 91] 2014/07/26 10:46:22 Sphero Changing Direction 306 GetRGB is [244 2 197] SetRGB is 37 196 9 PowerState is [255 255 0 8 9 1 2 3 28 0 43 6 73 82] 2014/07/26 10:46:32 Sphero Changing Direction 69 GetRGB is [37 196 9] SetRGB is 47 163 34
@tangsoft Yes it takes the sphero about half of a second to respond to your request, so you may not be able to request information from the sphero at the speed that you want.
We do plan on implementing more of the sphero API, and pull requests are graciously accepted! So if you've implemented more of the API, you're more than welcome to submit a pull request to the dev branch and we'll get it merged in.
I will merge this hotfix into the master branch and cut a new release.
@zankich cool. let me close this case at first.
Hi, I tried the GetRGB function, but can not get regular response output. fmt.Println("GetRGB is", driver.GetRGB())
sometimes, the output of GetRGB is empty, like this: 2014/07/25 16:30:33 Sphero Changing Direction 273 GetRGB is [] SetRGB is 226 248 202
Usually, after some loops running, it can return part of or all the reponse packets: 2014/07/25 15:53:36 Sphero Changing Direction 109 GetRGB is [255 255 0 169 4 4 229 215 146] SetRGB is 63 137 234 PowerState is [255 255 0 176 9 1 2 3 6 0 42 10 47 215] 2014/07/25 15:53:46 Sphero Changing Direction 28 GetRGB is [255 255 0 172 1 82] SetRGB is 75 63 25 PowerState is [255 255 0 177 1 77] 2014/07/25 15:53:56 Sphero Changing Direction 29 GetRGB is [255 255 0 177 4 63 137 234 152] SetRGB is 11 224 1 PowerState is [255 255 0 184 9 1 2 3 5 0 42 10 67 188] 2014/07/25 15:54:06 Sphero Changing Direction 81 GetRGB is [255 255 0 180 1 74] SetRGB is 197 186 184