FRCTeam1073-TheForceTeam / robot14

The codebase for C++ Robot code for th 2014 competition bot.
3 stars 0 forks source link

Use Sync Groups on CANJaguars #1

Closed evinugur closed 10 years ago

evinugur commented 10 years ago

WPILib has a feature on the CANJaguar class called sync groups. When a bunch of jags are on a given sync group, they'll all receive their data nearly simultaneously. The information describing which syncgroup is being used is a byte parameter that is implicitly set to 0 on each call to CANJaguar::Set. By default having everything on the same sync group provides little utilities. But for things where precision is needed, like our mecanum drive, it would be advantageous for all of those jags to share a syncgroup.

The SmartCANJaguar class has an implicit parameter set on construction for a sync group. Then, in SmartCANJaguar's Set method, it'll automatically pass the syncgroup variable it retains into CANJaguar::Set. This means that anytime you call SmartCANJaguar::Set, a sync group would be specified.

The only jags we have on the robot now are for mecanum drive, but if we set the jags to a non-default syncgroup, we'll know for sure that any other SmartCANJaguars that we might add down the line will not have to worry about them sharing the default sync group with the drive jags.

So, tl;dr

Give the mecanum jag objects a shared nonzero syncgroup.

Since we have robot builder, we probably can't use the constructor since the jags will get repaved. Instead, call SmartCANJaguar::SetSyncGroup(int) on the objects outside of the RobotBuilder comments.

evinugur commented 10 years ago

This has been implemented.

SyncGroups take a byte and are represented by a bit flag for each group (ie group one would be 0x1, 8 would be 0x8 or 10000000). They're stored in an enum in SmartCANJaguar. You have to pass them into a call to SmartCANJaguar::Set and call CANJaguar::UpdateSyncGroups after you make your set calls.

You can also bitwise or multiple sync groups to make a jag be a part of multiple sync groups. static methods exist in SmartCANJaguar to do that. These CANJaguars are just radiating with intellect now.