-
Notifications
You must be signed in to change notification settings - Fork 82
Expose individual wheel distances and velocities. #19
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,8 @@ namespace create { | |
| powerLEDIntensity = 0; | ||
| prevTicksLeft = 0; | ||
| prevTicksRight = 0; | ||
| totalLeftDist = 0.0; | ||
| totalRightDist = 0.0; | ||
| firstOnData = true; | ||
| pose.x = 0; | ||
| pose.y = 0; | ||
|
|
@@ -104,9 +106,9 @@ namespace create { | |
| deltaYaw = ((int16_t) GET_DATA(ID_ANGLE)) * (util::PI / 180.0); // D2R | ||
| deltaX = deltaDist * cos( util::normalizeAngle(pose.yaw + deltaYaw) ); | ||
| deltaY = -deltaDist * sin( util::normalizeAngle(pose.yaw + deltaYaw) ); | ||
| leftWheelDist = deltaDist / 2.0; | ||
| rightWheelDist = leftWheelDist; | ||
|
|
||
| const float deltaYawWheelDist = (util::CREATE_1_AXLE_LENGTH / 2.0) * deltaYaw; | ||
| leftWheelDist = deltaDist - deltaYawWheelDist; | ||
| rightWheelDist = deltaDist + deltaYawWheelDist; | ||
| } | ||
| else if (model == CREATE_2) { | ||
| // Get cumulative ticks (wraps around at 65535) | ||
|
|
@@ -149,6 +151,9 @@ namespace create { | |
| } | ||
| } // if CREATE_2 | ||
|
|
||
| totalLeftDist += leftWheelDist; | ||
| totalRightDist += rightWheelDist; | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can compute the individual wheel velocities here. |
||
| if (fabs(dt) > util::EPS) { | ||
| vel.x = deltaDist / dt; | ||
| vel.y = 0.0; | ||
|
|
@@ -863,6 +868,40 @@ namespace create { | |
| } | ||
| } | ||
|
|
||
| float Create::getLeftWheelDistance() const { | ||
| return totalLeftDist; | ||
| } | ||
|
|
||
| float Create::getRightWheelDistance() const { | ||
| return totalRightDist; | ||
| } | ||
|
|
||
| float Create::getRequestedLeftWheelVel() const { | ||
| if (data->isValidPacketID(ID_LEFT_VEL)) { | ||
| uint16_t uvel = GET_DATA(ID_LEFT_VEL); | ||
| int16_t vel; | ||
| std::memcpy(&vel, &uvel, sizeof(vel)); | ||
| return (vel / 1000.0); | ||
| } | ||
| else { | ||
| CERR("[create::Create] ", "Left wheel velocity not supported!"); | ||
| return 0; | ||
| } | ||
| } | ||
|
|
||
| float Create::getRequestedRightWheelVel() const { | ||
| if (data->isValidPacketID(ID_RIGHT_VEL)) { | ||
| uint16_t uvel = GET_DATA(ID_RIGHT_VEL); | ||
| int16_t vel; | ||
| std::memcpy(&vel, &uvel, sizeof(vel)); | ||
| return (vel / 1000.0); | ||
| } | ||
| else { | ||
| CERR("[create::Create] ", "Right wheel velocity not supported!"); | ||
| return 0; | ||
| } | ||
| } | ||
|
|
||
| create::CreateMode Create::getMode() const { | ||
| if (data->isValidPacketID(ID_OI_MODE)) { | ||
| return (create::CreateMode) GET_DATA(ID_OI_MODE); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
It may not be a serious issue, but there is potential for a wraparound here if someone is running the robot for the long term resulting in a negative distance.
You can disregard this issue for now, since the same problem exists in the global pose of the robot.
Uh oh!
There was an error while loading. Please reload this page.
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.
Since these are floats, the value wouldn't wrap around, it would just become +/- infinity. The bigger issue here is loss of precision. I did some quick tests and it looks like the precision (theoretically, I don't know how precise the measurements actually are) would get to about 1 mm after the robot travelled around 10 km. It wouldn't actually overflow unless it drove beyond the edge of the galaxy.