Skip to content

Commit a4a50c5

Browse files
committed
Add documentation
1 parent 87b3e8f commit a4a50c5

File tree

9 files changed

+218
-47
lines changed

9 files changed

+218
-47
lines changed

LICENSE

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright 2020 Tejas Mehta <[email protected]>
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
## Odometry Core
2+
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
3+
4+
This is a library made to handle the core mathematical calculations for three wheel Odometry.
5+
6+
This library requires either a value in encoder ticks, paired with the counts per revolution per encoder, or an inch value for each encoder to be given
7+
8+
## Installation (Gradle)
9+
In order to use this library, paste the following code under your ``allprojects/repositories``:
10+
11+
```
12+
allprojects {
13+
repositories {
14+
jcenter()
15+
maven { url "https://jitpack.io" } //Add this line
16+
}
17+
}
18+
```
19+
20+
Then place the following line under your ```dependencies```:
21+
```
22+
dependencies {
23+
implementation 'com.github.tmthecoder:OdometryCore:1.0.0'
24+
}
25+
```
26+
## Installation (JAR)
27+
28+
Alternatively, you can use the provided JAR in the releases section under the latest released version
29+
30+
## Usage
31+
32+
**Library Initialization:**
33+
```
34+
OdometryCore.initialize(cpr, diameter, leftOffet, rightOffset, frontBackOffset);
35+
```
36+
The parameters seen are:
37+
- cpr: The counts per revolution for the encoders you are using
38+
- diameter: The diameter of the wheels on the encoder
39+
- leftOffset: The offset of the left wheel from the center of the robot (only horizontal offset)
40+
- rightOffset: The offset of the right wheel from the center of the robot (only horizontal offset)
41+
- frontBackOffset: The offset of the front or back encoder wheel (only vertical offset)
42+
43+
**Position Tracking:**
44+
45+
After initializing, the robot's position can be found using the following code:
46+
```
47+
EncoderPositions encoderPositions = new EncoderPositions(leftPosition, rightPosition, frontBackPosition);
48+
OdometryPosition position = OdometryCore.getInstance().getCurrentPosition(encoderPositions);
49+
```
50+
The parameters seen are:
51+
- leftPosition: The left encoder's position in ticks
52+
- rightPosition: The right encoder's position in ticks
53+
- frontBackPosition: The front or back encoder's position in ticks
54+
55+
The position tracking code should be run on a loop with as small an interval as possible, and if possible on a separate thread
56+
57+
## Features and Bugs
58+
Please file feature requests and bugs at the [issue tracker].
59+
60+
[issue tracker]: https://github.com/tmthecoder/OdometryCore/issues
61+
62+
## Licensing
63+
64+
OdometryCore is Licensed under the [MIT License]
65+
66+
[MIT License]: https://github.com/tmthecoder/OdometryCore/blob/main/LICENSE

src/main/java/com/tejasmehta/OdometryCore/OdometryCore.java

+36-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
import com.tejasmehta.OdometryCore.localization.OdometryPosition;
66
import com.tejasmehta.OdometryCore.math.CoreMath;
77

8+
/**
9+
* @author Tejas Mehta
10+
* Made on Wednesday, November 04, 2020
11+
* File Name: Odometrycore
12+
* The main class to wrap over all odometry calculations
13+
*/
814
public class OdometryCore {
915

1016
private final double wheelDiameter;
@@ -18,6 +24,14 @@ public class OdometryCore {
1824
private double frontBackInches = 0;
1925
private OdometryPosition position = new OdometryPosition(0, 0, 0, HeadingUnit.RADIANS);
2026

27+
/**
28+
* Private constructor for local instance construction
29+
* @param cpr - The counts per rotation for the encoders
30+
* @param wheelDiameter - The encoder wheel's diameter (in inches)
31+
* @param leftOffset - The left encoder's offset from the center (in inches)
32+
* @param rightOffset - The right wheel's offset from the center (in inches)
33+
* @param frontBackOffset - The front or back wheel's offset from the center (in inches)
34+
*/
2135
private OdometryCore(double cpr, double wheelDiameter, double leftOffset, double rightOffset, double frontBackOffset) {
2236
this.wheelDiameter = wheelDiameter;
2337
this.cpr = cpr;
@@ -26,20 +40,41 @@ private OdometryCore(double cpr, double wheelDiameter, double leftOffset, double
2640
this.frontBackOffset = frontBackOffset;
2741
}
2842

29-
43+
/**
44+
* The static instance getter
45+
* @throws IllegalArgumentException if there is no instance made
46+
* @return - The current instance of OdometryCore
47+
*/
3048
public static OdometryCore getInstance() {
3149
if (instance == null) throw new IllegalArgumentException("Please initialize OdometryCore with OdometryCore.initialize(cpr, wheelDiameter, leftOffset, rightOffset, frontBackOffset)");
3250
return instance;
3351
}
3452

53+
/**
54+
* A method to initialize the static OdometryCore instance
55+
* @param cpr - The counts per rotation for the encoders
56+
* @param wheelDiameter - The encoder wheel's diameter (in inches)
57+
* @param leftOffset - The left encoder's offset from the center (in inches)
58+
* @param rightOffset - The right wheel's offset from the center (in inches)
59+
* @param frontBackOffset - The front or back wheel's offset from the center (in inches)
60+
*/
3561
public static void initialize(double cpr, double wheelDiameter, double leftOffset, double rightOffset, double frontBackOffset) {
3662
instance = new OdometryCore(cpr, wheelDiameter, leftOffset, rightOffset, frontBackOffset);
3763
}
3864

65+
/**
66+
* A checker to see whether the core is initialized
67+
* @return - A boolean signifying whether the core is initialized
68+
*/
3969
public static boolean isInitialized() {
4070
return instance != null;
4171
}
4272

73+
/**
74+
* A method to get the current position using three wheel odometry
75+
* @param positions - The robot's three encoder's positions
76+
* @return - The Position of the robot with an x, y, and heading
77+
*/
4378
public OdometryPosition getCurrentPosition(EncoderPositions positions) {
4479
double newLeftInches = CoreMath.ticksToInches(positions.getLeftPosition(), cpr, wheelDiameter);
4580
double newRightInches = CoreMath.ticksToInches(positions.getRightPosition(), cpr, wheelDiameter);

src/main/java/com/tejasmehta/OdometryCore/localization/EncoderPositions.java

+21-10
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,48 @@
1+
package com.tejasmehta.OdometryCore.localization;
2+
13
/****
2-
* Made by Tejas Mehta
4+
* @author Tejas Mehta
35
* Made on Wednesday, November 11, 2020
4-
* File Name: EncoderTicks
5-
* Package: com.tejasmehta.OdometryCore.localization
6+
* File Name: EncoderPositions
7+
* A class to unify all three encoder positions used in the core calculations
68
*/
7-
package com.tejasmehta.OdometryCore.localization;
8-
99
public class EncoderPositions {
1010
private final double leftPosition;
1111
private final double rightPosition;
1212
private final double frontBackPosition;
1313

1414
/**
15-
* A wrapper for encoder positions
16-
* @param leftPosition
17-
* @param rightPosition
18-
* @param frontBackPosition
15+
* The constructor for the encoder positions class
16+
* @param leftPosition - The left encoder's position in ticks
17+
* @param rightPosition - The right encoder's position in ticks
18+
* @param frontBackPosition - The Front or back encoder's position in ticks
1919
*/
2020
public EncoderPositions(double leftPosition, double rightPosition, double frontBackPosition) {
2121
this.leftPosition = leftPosition;
2222
this.rightPosition = rightPosition;
2323
this.frontBackPosition = frontBackPosition;
2424
}
2525

26-
26+
/**
27+
* A method to get the left encoder's position
28+
* @return - The left encoder's position (in ticks)
29+
*/
2730
public double getLeftPosition() {
2831
return leftPosition;
2932
}
3033

34+
/**
35+
* A method to get the right encoder's position
36+
* @return - The right encoder's position (in ticks)
37+
*/
3138
public double getRightPosition() {
3239
return rightPosition;
3340
}
3441

42+
/**
43+
* A method to get the front or back encoder's position
44+
* @return - The front or back encoder's position (in ticks)
45+
*/
3546
public double getFrontBackPosition() {
3647
return frontBackPosition;
3748
}

src/main/java/com/tejasmehta/OdometryCore/localization/HeadingUnit.java

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
1-
/****
2-
* Made by Tejas Mehta
3-
* Made on Wednesday, November 11, 2020
4-
* File Name: HeadingUnit
5-
* Package: org.firstinspires.ftc.teamcode.testCode.odometryCoreTest.localization*/
61
package com.tejasmehta.OdometryCore.localization;
72

83
/****
9-
* Made by Tejas Mehta
4+
* @author Tejas Mehta
105
* Made on Wednesday, November 04, 2020
116
* File Name: OdometryPosition
12-
* Package: com.tejasmehta.com.tejasmehta.OdometryCore.localization
7+
* An emun for the heading unit used in the OdometryPosition
138
*/
14-
159
public enum HeadingUnit {
1610
DEGREES,
1711
RADIANS

src/main/java/com/tejasmehta/OdometryCore/localization/OdometryPosition.java

+28-5
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,59 @@
1+
package com.tejasmehta.OdometryCore.localization;
2+
13
/****
2-
* Made by Tejas Mehta
3-
* Made on Wednesday, November 12, 2020
4+
* @author Tejas Mehta
5+
* Made on Thursday, November 12, 2020
46
* File Name: EncoderTicks
5-
* Package: com.tejasmehta.OdometryCore.localization
7+
* A class to store the Odometry position in the format of an x coordinate, a y coordinate, and an angle measure
68
*/
7-
package com.tejasmehta.OdometryCore.localization;
8-
99
public class OdometryPosition {
1010
private final double x;
1111
private final double y;
1212
private final double heading;
1313
private final HeadingUnit unit;
1414

15+
/**
16+
* The constructor for the OdometryPosition class
17+
* @param x - The x value on a cartesian plane (in inches)
18+
* @param y - The y value on a cartesian plane (in inches)
19+
* @param heading - The robot's current heading (in degrees or radians)
20+
* @param unit - The unit for the heading (either HeadingUnit.degrees or HeadingUnit.radians)
21+
*/
1522
public OdometryPosition(double x, double y, double heading, HeadingUnit unit) {
1623
this.x = x;
1724
this.y = y;
1825
this.heading = heading;
1926
this.unit = unit;
2027
}
2128

29+
/**
30+
* A getter for the x value
31+
* @return - The robot's x value (in inches)
32+
*/
2233
public double getX() {
2334
return x;
2435
}
2536

37+
/**
38+
* A getter for the y value
39+
* @return - The robot's y value (in inches)
40+
*/
2641
public double getY() {
2742
return y;
2843
}
2944

45+
/**
46+
* A getter for the robot's heading
47+
* @return - The robot's heading (in degrees)
48+
*/
3049
public double getHeadingDegrees() {
3150
return unit == HeadingUnit.DEGREES ? heading : Math.toDegrees(heading);
3251
}
3352

53+
/**
54+
* A getter for the robot's heading
55+
* @return - The robot's heading (in radians)
56+
*/
3457
public double getHeadingRadians() {
3558
return unit == HeadingUnit.RADIANS ? heading : Math.toDegrees(heading);
3659
}

src/main/java/com/tejasmehta/OdometryCore/math/CartesianCoordinate.java

+26-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
1+
package com.tejasmehta.OdometryCore.math;
2+
13
/****
2-
* Made by Tejas Mehta
4+
* @author Tejas Mehta
35
* Made on Wednesday, November 04, 2020
46
* File Name: LocalCoordinate
5-
* Package: com.tejasmehta.OdometryCore.math
7+
* A class to signify a cartesian coordinate and to simplify polar and cartesian operations
68
*/
7-
package com.tejasmehta.OdometryCore.math;
8-
99
public class CartesianCoordinate {
1010
private final double x;
1111
private final double y;
1212

13+
/**
14+
* A method to create a CartesianCoordinate from a given PolarCoordinate
15+
* @param polar - The polar coordinate to convert to a cartesian one
16+
* @return - The cartesian coordinate of the polar value
17+
*/
1318
public static CartesianCoordinate fromPolar(PolarCoordinate polar) {
1419
double r = polar.getR();
1520
double theta = polar.getTheta();
@@ -18,19 +23,36 @@ public static CartesianCoordinate fromPolar(PolarCoordinate polar) {
1823
return new CartesianCoordinate(x, y);
1924
}
2025

26+
/**
27+
* The constructor for a the CartesianCoordinate class
28+
* @param x - The x value of the coordinate
29+
* @param y - The y value of the coordinate
30+
*/
2131
public CartesianCoordinate(double x, double y) {
2232
this.x = x;
2333
this.y = y;
2434
}
2535

36+
/**
37+
* A getter for the coordinate's x value
38+
* @return - the coordinate's x value
39+
*/
2640
public double getX() {
2741
return x;
2842
}
2943

44+
/**
45+
* A getter for the coordinate's y value
46+
* @return - the coordinate's y value
47+
*/
3048
public double getY() {
3149
return y;
3250
}
3351

52+
/**
53+
* Method to handle toString calls on the object
54+
* @return - A string with the coordinates x and y values
55+
*/
3456
@Override
3557
public String toString() {
3658
return "CartesianCoordinate{" +

0 commit comments

Comments
 (0)