-
Notifications
You must be signed in to change notification settings - Fork 2
Slipping detection #193
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
Open
alvynw
wants to merge
4
commits into
master
Choose a base branch
from
slipping-detection
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Slipping detection #193
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
6 changes: 3 additions & 3 deletions
6
...potassium/commons/position/Position.scala → .../commons/cartesianPosition/Position.scala
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
40 changes: 40 additions & 0 deletions
40
commons/src/main/scala/com/lynbrookrobotics/potassium/commons/position/Slipping.scala
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 |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| package com.lynbrookrobotics.potassium.commons.position | ||
|
|
||
| import com.lynbrookrobotics.potassium.streams._ | ||
| import squants.Velocity | ||
| import squants.motion.{Acceleration, AngularVelocity} | ||
| import squants.space.{Feet, Length} | ||
|
|
||
| object Slipping { | ||
| def slippingDetection (angularVelocity: Stream[AngularVelocity], | ||
| linearAcceleration: Stream[Acceleration], | ||
| leftEncoderVelocity: Stream[Velocity], | ||
| rightEncoderVelocity: Stream[Velocity], | ||
| distanceFromAccelerometerLeft: Length, | ||
| distanceFromAccelerometerRight: Length, | ||
| allowedAccelerationDeviation: Acceleration): Stream[(Boolean, Boolean)] = { | ||
| val radius = linearAcceleration.zip(angularVelocity.derivative).map{ case(linearAcc, angularAcc) => | ||
| Feet(linearAcc.toFeetPerSecondSquared / angularAcc.toRadiansPerSecondSquared) | ||
| } | ||
|
|
||
| val leftRadius = radius.map(_ - distanceFromAccelerometerLeft) | ||
| val rightRadius = radius.map(_ + distanceFromAccelerometerRight) | ||
|
|
||
| val leftCalculatedAcceleration: Stream[Acceleration] = leftRadius.zip(angularVelocity.derivative).map{ case(radius, angularAcc) => | ||
| angularAcc onRadius radius | ||
| } | ||
| val rightCalculatedAcceleration = rightRadius.zip(angularVelocity.derivative).map{ case(radius, angularAcc) => | ||
| angularAcc onRadius radius | ||
| } | ||
|
|
||
| val leftIsSlipping = leftCalculatedAcceleration.zip(leftEncoderVelocity.derivative).map{ case(calculatedAcc, actualAcc) => | ||
| (calculatedAcc - actualAcc).abs > allowedAccelerationDeviation | ||
| } | ||
|
|
||
| val rightIsSlipping = rightCalculatedAcceleration.zip(rightEncoderVelocity.derivative).map{ case(calculatedAcc, actualAcc) => | ||
| (calculatedAcc - actualAcc).abs > allowedAccelerationDeviation | ||
| } | ||
|
|
||
| leftIsSlipping.zip(rightIsSlipping) | ||
| } | ||
| } |
123 changes: 123 additions & 0 deletions
123
commons/src/test/scala/com/lynbrookrobotics/potassium/commons/drivetrain/SlippingTest.scala
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 |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| package com.lynbrookrobotics.potassium.commons.drivetrain | ||
|
|
||
| import com.lynbrookrobotics.potassium.ClockMocking | ||
| import com.lynbrookrobotics.potassium.streams.Stream | ||
| import com.lynbrookrobotics.potassium.commons.position.Slipping | ||
| import org.scalatest.FunSuite | ||
| import squants.Velocity | ||
| import squants.motion._ | ||
| import squants.space.{Feet, Length} | ||
| import squants.time.Milliseconds | ||
|
|
||
| class SlippingTest extends FunSuite { | ||
|
|
||
| implicit val (clock, triggerClock) = ClockMocking.mockedClockTicker | ||
| val period = Milliseconds(5) | ||
|
|
||
| test("left and right slipping") { | ||
| val angularVelocity: Stream[AngularVelocity] = Stream.periodic(period)(RadiansPerSecondSquared(5)).integral | ||
| val linearAcceleration: Stream[Acceleration] = Stream.periodic(period)(FeetPerSecondSquared(5)) | ||
| val leftEncoderVelocity: Stream[Velocity] = Stream.periodic(period)(FeetPerSecondSquared(2)).integral | ||
| val rightEncoderVelocity: Stream[Velocity] = Stream.periodic(period)(FeetPerSecondSquared(9.5)).integral | ||
|
Contributor
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. Please use smaller, easier to compute numbers to avoid mistakes in unit tests. |
||
| val distanceFromAccelerometerLeft: Length = Feet(0.5) // calc = 2.5 | ||
| val distanceFromAccelerometerRight: Length = Feet(1) // calc = 10 | ||
| val allowedAccelerationDeviation: Acceleration = MetersPerSecondSquared(1) | ||
|
|
||
| val isSlipping = Slipping.slippingDetection(angularVelocity, | ||
| linearAcceleration, | ||
| leftEncoderVelocity, | ||
| rightEncoderVelocity, | ||
| distanceFromAccelerometerLeft, | ||
| distanceFromAccelerometerRight, | ||
| allowedAccelerationDeviation) | ||
| isSlipping.foreach(x => assert(!x._1 && !x._2)) | ||
|
|
||
| triggerClock.apply(period) | ||
| triggerClock.apply(period) | ||
| triggerClock.apply(period) | ||
|
Contributor
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. Why do you call apply so many times? |
||
| triggerClock.apply(period) | ||
| triggerClock.apply(period) | ||
| triggerClock.apply(period) | ||
| } | ||
|
|
||
| test("left and right not slipping") { | ||
| val angularVelocity: Stream[AngularVelocity] = Stream.periodic(period)(RadiansPerSecondSquared(5)).integral | ||
| val linearAcceleration: Stream[Acceleration] = Stream.periodic(period)(FeetPerSecondSquared(5)) | ||
| val leftEncoderVelocity: Stream[Velocity] = Stream.periodic(period)(FeetPerSecondSquared(2)).integral | ||
| val rightEncoderVelocity: Stream[Velocity] = Stream.periodic(period)(FeetPerSecondSquared(9.5)).integral | ||
| val distanceFromAccelerometerLeft: Length = Feet(0.5) // calc = 2.5 | ||
| val distanceFromAccelerometerRight: Length = Feet(1) // calc = 10 | ||
| val allowedAccelerationDeviation: Acceleration = MetersPerSecondSquared(0.1) | ||
|
|
||
| val isSlipping = Slipping.slippingDetection(angularVelocity, | ||
| linearAcceleration, | ||
| leftEncoderVelocity, | ||
| rightEncoderVelocity, | ||
| distanceFromAccelerometerLeft, | ||
| distanceFromAccelerometerRight, | ||
| allowedAccelerationDeviation) | ||
|
|
||
| isSlipping.foreach(x => assert(x._1 && x._2)) | ||
|
|
||
| triggerClock.apply(period) | ||
| triggerClock.apply(period) | ||
| triggerClock.apply(period) | ||
| triggerClock.apply(period) | ||
| triggerClock.apply(period) | ||
| triggerClock.apply(period) | ||
| } | ||
|
|
||
| test("right slipping only") { | ||
| val angularVelocity: Stream[AngularVelocity] = Stream.periodic(period)(RadiansPerSecondSquared(5)).integral | ||
| val linearAcceleration: Stream[Acceleration] = Stream.periodic(period)(FeetPerSecondSquared(5)) | ||
| val leftEncoderVelocity: Stream[Velocity] = Stream.periodic(period)(FeetPerSecondSquared(2)).integral | ||
| val rightEncoderVelocity: Stream[Velocity] = Stream.periodic(period)(FeetPerSecondSquared(30)).integral | ||
| val distanceFromAccelerometerLeft: Length = Feet(0.5) // calc = 2.5 | ||
| val distanceFromAccelerometerRight: Length = Feet(1) // calc = 10 | ||
| val allowedAccelerationDeviation: Acceleration = MetersPerSecondSquared(1) | ||
|
|
||
| val isSlipping = Slipping.slippingDetection(angularVelocity, | ||
| linearAcceleration, | ||
| leftEncoderVelocity, | ||
| rightEncoderVelocity, | ||
| distanceFromAccelerometerLeft, | ||
| distanceFromAccelerometerRight, | ||
| allowedAccelerationDeviation) | ||
|
|
||
| isSlipping.foreach(x => assert(!x._1 && x._2)) | ||
|
|
||
| triggerClock.apply(period) | ||
| triggerClock.apply(period) | ||
| triggerClock.apply(period) | ||
| triggerClock.apply(period) | ||
| triggerClock.apply(period) | ||
| triggerClock.apply(period) | ||
| } | ||
|
|
||
| test("left slipping only") { | ||
| val angularVelocity: Stream[AngularVelocity] = Stream.periodic(period)(RadiansPerSecondSquared(5)).integral | ||
| val linearAcceleration: Stream[Acceleration] = Stream.periodic(period)(FeetPerSecondSquared(5)) | ||
| val leftEncoderVelocity: Stream[Velocity] = Stream.periodic(period)(FeetPerSecondSquared(30)).integral | ||
| val rightEncoderVelocity: Stream[Velocity] = Stream.periodic(period)(FeetPerSecondSquared(9.5)).integral | ||
| val distanceFromAccelerometerLeft: Length = Feet(0.5) // calc = 2.5 | ||
| val distanceFromAccelerometerRight: Length = Feet(1) // calc = 10 | ||
| val allowedAccelerationDeviation: Acceleration = MetersPerSecondSquared(1) | ||
|
|
||
| val isSlipping = Slipping.slippingDetection(angularVelocity, | ||
| linearAcceleration, | ||
| leftEncoderVelocity, | ||
| rightEncoderVelocity, | ||
| distanceFromAccelerometerLeft, | ||
| distanceFromAccelerometerRight, | ||
| allowedAccelerationDeviation) | ||
|
|
||
| isSlipping.foreach(x => assert(x._1 && !x._2)) | ||
|
|
||
| triggerClock.apply(period) | ||
| triggerClock.apply(period) | ||
| triggerClock.apply(period) | ||
| triggerClock.apply(period) | ||
| triggerClock.apply(period) | ||
| triggerClock.apply(period) | ||
| } | ||
| } | ||
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.
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.
Please include more descriptive test names that describe the specific parameters and conditions you are testing. For example, "test no slipping detected with no linear or angular acceleration