-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
sphero(r2d2): support the R2D2 sphero bot #1189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
| @@ -0,0 +1,271 @@ | |||
| package sphero | |||
|
|
|||
| type Audio uint16 | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
opted to put these in a different file being that there are quite a few Audio and Animation options
|
|
||
| // GetLocatorData calls the passed function with the data from the locator | ||
| func (d *R2D2Driver) GetLocatorData(f func(p Point2D)) { | ||
| // CID 0x15 is the code for the locator request |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was copied from the Ollie driver, I think the R2 uses a different CID. I need to add a TODO here
| func (d *R2D2Driver) GetPowerState(f func(p spherocommon.PowerStatePacket)) { | ||
| // did: 19, cid: 4 | ||
| d.sendCraftPacket([]uint8{}, 0x13, 0x04) | ||
| // CHARGED = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are notes I copied from the spherov2 python lib. I might want to add them to the api docs as a short term fix or implement this correctly in a future commit.
| } | ||
|
|
||
| // avoid ddos the r2 | ||
| time.Sleep(commandInterval) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't see a Sleep in used in other sphero drivers but it avoids the write channel from writing out of sequence. The python lib does something similar.
|
|
||
| log.Printf("processing asyncMessage: % X", d.asyncMessage) | ||
|
|
||
| //TODO get sensor data from a packet starting with 0x8d 0x0 0x18 0x2 0xff |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
more work needs to be done here. I could see us doing something similar to the python lib were the response stores local sensor variables that can be used by clients calling a simple GetLocation(): X, Y that returns the stored sensor data. A sample sensor packet looks like this:
0x8d 0x0 0x18 0x2 0xff 0x41 0x8a 0x5e 0x2f 0x3e 0x61 0x39 0xe3 0x3f 0x2c 0xf5 0x95 0x3b 0xcf 0x4 0x60 0xbe 0x9b 0x13 0xc0 0x3f 0x78 0x68 0x65 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x80 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0xbd 0xfa 0xe7 0xa4 0xbd 0xa2 0xee 0xda 0x0 0x0 0x0 0x0 0xd7 0xd8
| d.seqMutex.Lock() | ||
| defer d.seqMutex.Unlock() | ||
|
|
||
| //TODO handle flags, tid, sid err better |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I probably should just remove this TODO, I haven't seen a need to handle request Flags or TID, SID optional packet parts.
| return append(escaped, b) | ||
| } | ||
|
|
||
| func unescapeBytes(data []uint8) []uint8 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will be used during handleResponse, though it's not currently referenced.
|
@gen2thomas sorry for all of the linting issues. I haven't been able my linter working locally where it catches some of these before I push changes. |
|
@cannino please can you also inspect your own comments and mark them as resolved or update the content, if possible. |
Solved issues and/or description of the change
Adds support for the R2D2 sphero droid. Much of the PR has been inspired by the spherov2 python library here
...
Manual test
Checklist
make test_race)make fmt_check)If this is a new driver or adaptor:
make examples_check)If this is a Go version or module update:
If this is a PR for release: