Skip to content

Conversation

@cannino
Copy link

@cannino cannino commented Oct 26, 2025

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

  • OS and Version (Win/Mac/Linux): Mac
  • Adaptor(s) and/or driver(s): bleclient.Adaptor, sphero.R2D2Driver

Checklist

  • The PR's target branch is 'hybridgroup:dev'
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes (e.g. by run make test_race)
  • No linter errors exist locally (e.g. by run make fmt_check)
  • I have performed a self-review of my own code

If this is a new driver or adaptor:

  • I have added the name to the corresponding README.md
  • I have added an example to see how to setup and use it
  • I have checked or build at least my new example (e.g. by run make examples_check)

If this is a Go version or module update:

  • go.mod to new version updated
  • modules updated (go get -u -t ./...)
  • CI files updated
  • linter setting and linter version (if a newer one exist) updated
  • linter issues fixed or suppressed by config

If this is a PR for release:

  • The PR's target branch is 'hybridgroup:release'
  • I have adjusted the CHANGELOG.md (or already prepared and will be merged as soon as possible)

@@ -0,0 +1,271 @@
package sphero

type Audio uint16
Copy link
Author

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
Copy link
Author

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
Copy link
Author

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)
Copy link
Author

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
Copy link
Author

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
Copy link
Author

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 {
Copy link
Author

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.

@cannino cannino marked this pull request as ready for review November 8, 2025 15:52
@cannino
Copy link
Author

cannino commented Nov 12, 2025

@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.

@gen2thomas
Copy link
Collaborator

@cannino please can you also inspect your own comments and mark them as resolved or update the content, if possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants