Skip to content
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

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open

Raph port #20

wants to merge 16 commits into from

Conversation

blu-exe
Copy link

@blu-exe blu-exe commented Nov 19, 2018

No description provided.


public class Path(filepath: String, backwards: Boolean = false) {

private var coordinates: MutableList<Vector2> = mutableListOf<Vector2>()
Copy link
Contributor

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>()
Copy link
Contributor

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

@BBScholar BBScholar Nov 19, 2018

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

Copy link
Contributor

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

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

Copy link
Contributor

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.

Copy link
Member

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.

Copy link
Contributor

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with Connor

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm

Copy link
Member

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.

Copy link
Contributor

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?

Copy link
Contributor

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

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

Copy link
Contributor

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

Copy link
Member

@andycate andycate Nov 19, 2018

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

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

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

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.

Copy link
Contributor

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

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)

Copy link
Author

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

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

Copy link
Member

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

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

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

Copy link
Contributor

@BBScholar BBScholar left a 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

Copy link
Member

@andycate andycate left a 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)
Copy link
Member

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see line 10

@codecov
Copy link

codecov bot commented Nov 26, 2018

Codecov Report

❗ No coverage uploaded for pull request base (master@c601786). Click here to learn what that means.
The diff coverage is 0.86%.

Impacted file tree graph

@@           Coverage Diff            @@
##             master     #20   +/-   ##
========================================
  Coverage          ?   1.36%           
  Complexity        ?       6           
========================================
  Files             ?      16           
  Lines             ?     657           
  Branches          ?      39           
========================================
  Hits              ?       9           
  Misses            ?     648           
  Partials          ?       0
Impacted Files Coverage Δ Complexity Δ
...in/frc/team5499/frc2018Kotlin/path/PathFollower.kt 0% <0%> (ø) 0 <0> (?)
...ain/kotlin/frc/team5499/frc2018Kotlin/path/Path.kt 0% <0%> (ø) 0 <0> (?)
...kotlin/frc/team5499/frc2018Kotlin/utils/Vector2.kt 31.81% <33.33%> (ø) 4 <1> (?)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c601786...d60d2a1. Read the comment docs.

Copy link
Contributor

@BBScholar BBScholar left a 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()) {
Copy link
Contributor

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) )

Copy link
Contributor

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

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use val please

Copy link
Contributor

@BBScholar BBScholar Nov 30, 2018

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

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.

4 participants