-
Notifications
You must be signed in to change notification settings - Fork 0
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
Raph port #20
base: master
Are you sure you want to change the base?
Conversation
new changes merged
|
||
public class Path(filepath: String, backwards: Boolean = false) { | ||
|
||
private var coordinates: MutableList<Vector2> = mutableListOf<Vector2>() |
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.
make this mCoordinates
public class Path(filepath: String, backwards: Boolean = false) { | ||
|
||
private var coordinates: MutableList<Vector2> = mutableListOf<Vector2>() | ||
private var targetVelocities: MutableList<Double> = mutableListOf<Double>() |
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.
make this mTargetVelocities
private var coordinates: MutableList<Vector2> = mutableListOf<Vector2>() | ||
private var targetVelocities: MutableList<Double> = mutableListOf<Double>() | ||
|
||
private var backwards: Boolean = false |
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.
if you're defaulting backwards
to false in the constructor, don't set it to false here. Make this line just private var backwards: Boolean
and then initialize it in the init
block
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.
make it public as well
} | ||
} catch (e: FileNotFoundException) { | ||
e.printStackTrace() | ||
System.exit(1) |
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.
Do we exit in the java code? I dont know If we should do that
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 this likely going to be used for autonomous, it makes since to keep running and fall back to a default mode. I think we should let the calling function catch the exception and decide what to do with it.
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.
yeah, it should exit. If the path can't be found, that is a fatal error. Causing the program to exit will force the programmer to resolve the issue before continuing.
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.
no, if it exits in auto, then we cant run in teleop either until the robot reboots.
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 agree with Connor
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.
hmm
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.
What 254 does is they package all the paths with the jar file. This is probably a better idea, because then the programmer is forced to update the paths locally, as well as catch any errors before the code will work. You will be less likely to run into issues with the paths being out of date or different versions on the robot.
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.
how do you package the paths with the jar?
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 know their 2017 code used actual java classes to represent paths
return Vector2.copyVector(coordinates[index]) | ||
} | ||
|
||
public fun isBackwards(): Boolean { |
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.
Use a kotlin getter
val backwards: Boolean get() = field
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.
that get function is on a new line with a tab
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.
val backwards: Boolean
get() = field
return tmp | ||
} | ||
|
||
public fun getPathLength(): Int { |
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.
make this getCoordinatesLength(): Int
or something because pathLength could be used for the literally length of the path
} | ||
@Suppress("ComplexMethod") | ||
private fun calculateLookahead(robotPos: Vector2, robotAngle: Double): Vector2 { | ||
mLastClosestPointIndex = mPath.findClosestPointIndex(robotPos, mLastClosestPointIndex) |
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.
indentation issue (?). maybe its just github
@@ -29,10 +29,51 @@ data class Vector2(val x: Double, val y: Double) { | |||
|
|||
fun distanceTo(other: Vector2) = (this - other).magnitude | |||
|
|||
fun getHeading(): Double { |
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.
isnt there an angle
variable in the vector2 class already? maybe Im wrong. If there isn't, make sure you test this method because it was taken from a different source (Mitchy Boi) so they may not be fully compatible.
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 is, figure out how to use that in this. idk if we even need the angle for the vector2 tbh. something to look at
fun unitDirectionVector(vector: Vector2): Vector2 = vector * 1.0 / vector.magnitude | ||
|
||
@Suppress("MagicNumber") | ||
fun copyVector(original: Vector2): Vector2 = Vector2(original.x, original.y) |
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.
you don't need this in kotlin if the class is a data class
(https://kotlinlang.org/docs/reference/data-classes.html)
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.
both?
fun distanceBetween(a: Vector2, b: Vector2) = (a - b).magnitude | ||
|
||
fun unitDirectionVector(vector: Vector2): Vector2 = vector * 1.0 / vector.magnitude |
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 is just the normalized vector.There is already a method for this in the vector2 class
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.
see line 10
Vector2(Math.cos(Math.toRadians(450 - heading)), Math.sin(Math.toRadians(450 - heading))) | ||
|
||
@Suppress("MagicNumber") | ||
fun angleBetween(from: Vector2, to: Vector2): Double { |
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.
refactor using angle
field of each vector
else -mPath.getPointVelocity(mLastClosestPointIndex) | ||
|
||
output[0] = averageVelocity * (2.0 + (curvature * Constants.TRACK_WIDTH)) / 2.0 | ||
output[1] = averageVelocity * (2.0 - (curvature * Constants.TRACK_WIDTH)) / 2.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.
Use a Pair<Double, Double>
for this instead of an array. its neater. you'll need to refactor in the auto command as well though
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.
Looks very good. Theres some small issues mostly related to styling. Fix indentation errors for OCS reasons (unless its just github deeking). You added some unnecessary functions to vector2
(probably). And fix the issue with ENCODER_TICKS_PER_ROTATION
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.
Overall, you've done a pretty good job. Just some organizational and syntax things to fix.
} | ||
return rawHeading | ||
} | ||
|
||
override fun toString(): String = "X: $x, Y: $y" | ||
|
||
companion object { | ||
val Zero = Vector2(0, 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.
make this ZERO
fun distanceBetween(a: Vector2, b: Vector2) = (a - b).magnitude | ||
|
||
fun unitDirectionVector(vector: Vector2): Vector2 = vector * 1.0 / vector.magnitude |
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.
see line 10
Codecov Report
@@ Coverage Diff @@
## master #20 +/- ##
========================================
Coverage ? 1.36%
Complexity ? 6
========================================
Files ? 16
Lines ? 657
Branches ? 39
========================================
Hits ? 9
Misses ? 648
Partials ? 0
Continue to review full report at Codecov.
|
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.
Very close to finished! Just one explicit error and the rest is just convention stuff
var t2: Double = (-b + dis) / (2.0 * a) | ||
mLastClosestPointIndex = mPath.findClosestPointIndex(robotPos, mLastClosestPointIndex) | ||
var lookahead: Vector2? = null | ||
for (i in mLastClosestPointIndex..mPath.getCoordinatesLength()) { |
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.
won't this throw an index out of range error since you're using mPath.getPoint(i + 1)
. Tt should probably be for (i in mLastClosestIndex..mPath.getCoordinatesLength() - 2)
(-2 because kotlin using inclusive ranges such as [0, 10] instead of [0, 11) )
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.
A unit test will help with this in the future
|
||
return output | ||
return Pair(leftOutput, rightOutput) |
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 would try using a data class
instead of a pair
to make this less ambiguous to read. https://kotlinlang.org/docs/reference/data-classes.html
for example you could define a public data class within the path follower class like public data class PathFollowerOutput(val leftVelocity: Double, val rightVelocity: Double)
(thats all you need) and then you could simply return it as PathFollowerOutput(leftOutput, rightOutput)
. Then, retrieving the values wont be as confusing later. It would be output.leftOutput
instead of output.first
. Personal opinion though.
|
||
private var backwards: Boolean = false | ||
private var backwards: Boolean |
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.
use val
please
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.
for mCoordinates
and mTargetVelocities
as well
No description provided.