Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
DifferentialDrive.cc File Reference

Unit test for DifferentialDrive algorithm class. More...

#include "../../../../src/algorithms/kinematics/DifferentialDrive.hpp"
#include "../../../../TestingBase.hh"
Include dependency graph for DifferentialDrive.cc:

Classes

class  DifferentialDriveTests
 Unit Test Class for the DifferentialDrive Planner. More...

Functions

 TEST_F (DifferentialDriveTests, TankDrive)
 Test DifferentialDrive TankDrive functionality.
 TEST_F (DifferentialDriveTests, TankDriveSquareInputs)
 Test DifferentialDrive TankDrive with square inputs.
 TEST_F (DifferentialDriveTests, ArcadeDrive)
 Test DifferentialDrive ArcadeDrive functionality.
 TEST_F (DifferentialDriveTests, ArcadeDriveSquareInputs)
 Test DifferentialDrive ArcadeDrive with square inputs.
 TEST_F (DifferentialDriveTests, CurvatureDrive)
 Test DifferentialDrive CurvatureDrive functionality.
 TEST_F (DifferentialDriveTests, CurvatureDriveSquareInputs)
 Test DifferentialDrive CurvatureDrive with square inputs.

Detailed Description

Unit test for DifferentialDrive algorithm class.

Author
ClayJay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2023-10-12

Function Documentation

◆ TEST_F() [1/6]

TEST_F ( DifferentialDriveTests ,
TankDrive  )

Test DifferentialDrive TankDrive functionality.

Author
ClayJay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2023-10-12
79{
80 // Create array for storing input and expect output values.
81 const int nTestValuesLength = 11;
82 const double aLeftSpeedInput[nTestValuesLength] = {-1.0, -0.5, 0.0, 0.5, 1.0, 1.0, 0.5, 0.0, -0.5, -1.0, 1.5};
83 const double aRightSpeedInput[nTestValuesLength] = {-1.0, -0.5, 0.0, 0.5, 1.0, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5};
84 const double aLeftSpeedOutput[nTestValuesLength] = {-1.0, -0.5, 0.0, 0.5, 1.0, 1.0, 0.5, 0.0, -0.5, -1.0, 1.0};
85 const double aRightSpeedOutput[nTestValuesLength] = {-1.0, -0.5, 0.0, 0.5, 1.0, -1.0, -0.5, 0.0, 0.5, 1.0, 1.0};
86
87 // Loop through each value and compare inputs and outputs.
88 for (int nIter = 0; nIter < nTestValuesLength; ++nIter)
89 {
90 // Calculate drive powers.
91 diffdrive::DrivePowers stDriveOutput = diffdrive::CalculateTankDrive(aLeftSpeedInput[nIter], aRightSpeedInput[nIter]);
92
93 // Check that the expected output values were calculated.
94 EXPECT_NEAR(aLeftSpeedOutput[nIter], stDriveOutput.dLeftDrivePower, 0.01); // Left output check.
95 EXPECT_NEAR(aRightSpeedOutput[nIter], stDriveOutput.dRightDrivePower, 0.01); // Right output check.
96 }
97}
DrivePowers CalculateTankDrive(double dLeftSpeed, double dRightSpeed, bool bSquareInputs=false)
Tank drive inverse kinematics for differential drive robots.
Definition DifferentialDrive.hpp:91
This struct is used to store the left and right drive powers for the robot. Storing these values in a...
Definition DifferentialDrive.hpp:73
Here is the call graph for this function:

◆ TEST_F() [2/6]

TEST_F ( DifferentialDriveTests ,
TankDriveSquareInputs  )

Test DifferentialDrive TankDrive with square inputs.

Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2025-03-04
107{
108 // Create array for storing input and expect output values.
109 const int nTestValuesLength = 11;
110 const double aLeftSpeedInput[nTestValuesLength] = {-1.0, -0.5, 0.0, 0.5, 1.0, 1.0, 0.5, 0.0, -0.5, -1.0, 1.5};
111 const double aRightSpeedInput[nTestValuesLength] = {-1.0, -0.5, 0.0, 0.5, 1.0, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5};
112 const double aLeftSpeedOutput[nTestValuesLength] = {-1.0, -0.25, 0.0, 0.25, 1.0, 1.0, 0.25, 0.0, -0.25, -1.0, 1.0};
113 const double aRightSpeedOutput[nTestValuesLength] = {-1.0, -0.25, 0.0, 0.25, 1.0, -1.0, -0.25, 0.0, 0.25, 1.0, 1.0};
114
115 // Loop through each value and compare inputs and outputs.
116 for (int nIter = 0; nIter < nTestValuesLength; ++nIter)
117 {
118 // Calculate drive powers.
119 diffdrive::DrivePowers stDriveOutput = diffdrive::CalculateTankDrive(aLeftSpeedInput[nIter], aRightSpeedInput[nIter], true);
120
121 // Check that the expected output values were calculated.
122 EXPECT_NEAR(aLeftSpeedOutput[nIter], stDriveOutput.dLeftDrivePower, 0.01); // Left output check.
123 EXPECT_NEAR(aRightSpeedOutput[nIter], stDriveOutput.dRightDrivePower, 0.01); // Right output check.
124 }
125}
Here is the call graph for this function:

◆ TEST_F() [3/6]

TEST_F ( DifferentialDriveTests ,
ArcadeDrive  )

Test DifferentialDrive ArcadeDrive functionality.

Author
ClayJay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2023-10-12
135{
136 // Create array for storing input and expect output values.
137 const int nTestValuesLength = 11;
138 const double aSpeedInput[nTestValuesLength] = {-1.0, -0.5, 0.0, 0.5, 1.0, 0.0, 0.0, 0.0, 0.0, 0.3, 1.5};
139 const double aRotationInput[nTestValuesLength] = {0.0, 0.0, 0.0, 0.0, 0.0, -1.0, -0.5, 0.5, 1.0, 1.0, 1.5};
140 const double aLeftSpeedOutput[nTestValuesLength] = {-1.0, -0.5, 0.0, 0.5, 1.0, -1.0, -0.5, 0.5, 1.0, 1.0, 1.0};
141 const double aRightSpeedOutput[nTestValuesLength] = {-1.0, -0.5, 0.0, 0.5, 1.0, 1.0, 0.5, -0.5, -1.0, -0.53, 0.0};
142
143 // Loop through each value and compare inputs and outputs.
144 for (int nIter = 0; nIter < nTestValuesLength; ++nIter)
145 {
146 // Calculate drive powers.
147 diffdrive::DrivePowers stDriveOutput = diffdrive::CalculateArcadeDrive(aSpeedInput[nIter], aRotationInput[nIter]);
148
149 // Check that the expected output values were calculated.
150 EXPECT_NEAR(aLeftSpeedOutput[nIter], stDriveOutput.dLeftDrivePower, 0.02); // Left output check.
151 EXPECT_NEAR(aRightSpeedOutput[nIter], stDriveOutput.dRightDrivePower, 0.02); // Right output check.
152 }
153}
DrivePowers CalculateArcadeDrive(double dSpeed, double dRotation, const bool bSquareInputs=false)
Arcade drive inverse kinematics for differential drive robots.
Definition DifferentialDrive.hpp:120
Here is the call graph for this function:

◆ TEST_F() [4/6]

TEST_F ( DifferentialDriveTests ,
ArcadeDriveSquareInputs  )

Test DifferentialDrive ArcadeDrive with square inputs.

Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2025-03-04
163{
164 // Create array for storing input and expect output values.
165 const int nTestValuesLength = 11;
166 const double aSpeedInput[nTestValuesLength] = {-1.0, -0.5, 0.0, 0.5, 1.0, 0.0, 0.0, 0.0, 0.0, 0.3, 1.5};
167 const double aRotationInput[nTestValuesLength] = {0.0, 0.0, 0.0, 0.0, 0.0, -1.0, -0.5, 0.5, 1.0, 1.0, 1.5};
168 const double aLeftSpeedOutput[nTestValuesLength] = {-1.0, -0.25, 0.0, 0.25, 1.0, -1.0, -0.25, 0.25, 1.0, 1.0, 1.0};
169 const double aRightSpeedOutput[nTestValuesLength] = {-1.0, -0.25, 0.0, 0.25, 1.0, 1.0, 0.25, -0.25, -1.0, -0.83, 0.0};
170
171 // Loop through each value and compare inputs and outputs.
172 for (int nIter = 0; nIter < nTestValuesLength; ++nIter)
173 {
174 // Calculate drive powers.
175 diffdrive::DrivePowers stDriveOutput = diffdrive::CalculateArcadeDrive(aSpeedInput[nIter], aRotationInput[nIter], true);
176
177 // Check that the expected output values were calculated.
178 EXPECT_NEAR(aLeftSpeedOutput[nIter], stDriveOutput.dLeftDrivePower, 0.02); // Left output check.
179 EXPECT_NEAR(aRightSpeedOutput[nIter], stDriveOutput.dRightDrivePower, 0.02); // Right output check.
180 }
181}
Here is the call graph for this function:

◆ TEST_F() [5/6]

TEST_F ( DifferentialDriveTests ,
CurvatureDrive  )

Test DifferentialDrive CurvatureDrive functionality.

Author
ClayJay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2023-10-13
191{
192 // Create array for storing input and expect output values.
193 const int nTestValuesLength = 11;
194 const double aSpeedInput[nTestValuesLength] = {-1.0, -0.5, 0.0, 0.5, 1.0, 0.0, 0.0, 0.0, 0.0, 0.3, 1.5};
195 const double aRotationInput[nTestValuesLength] = {0.0, 0.0, 0.0, 0.0, 0.0, -1.0, -0.5, 0.5, 1.0, 1.0, 1.5};
196 const bool aAllowTurnInPlaceInput[nTestValuesLength] = {true, true, true, true, true, true, true, true, true, true, true};
197 const double aLeftSpeedOutput[nTestValuesLength] = {-1.0, -0.5, 0.0, 0.5, 1.0, -1.0, -0.5, 0.5, 1.0, 0.59, 1.0};
198 const double aRightSpeedOutput[nTestValuesLength] = {-1.0, -0.5, 0.0, 0.5, 1.0, 1.0, 0.5, -0.5, -1.0, 0.0, 0.0};
199
200 // Loop through each value and compare inputs and outputs.
201 for (int nIter = 0; nIter < nTestValuesLength; ++nIter)
202 {
203 // Calculate drive powers.
204 diffdrive::DrivePowers stDriveOutput = diffdrive::CalculateCurvatureDrive(aSpeedInput[nIter], aRotationInput[nIter], aAllowTurnInPlaceInput[nIter]);
205
206 // Check that the expected output values were calculated.
207 EXPECT_NEAR(aLeftSpeedOutput[nIter], stDriveOutput.dLeftDrivePower, 0.02); // Left output check.
208 EXPECT_NEAR(aRightSpeedOutput[nIter], stDriveOutput.dRightDrivePower, 0.02); // Right output check.
209 }
210}
DrivePowers CalculateCurvatureDrive(double dSpeed, double dRotation, const bool bAllowTurnInPlace, const bool bSquareInputs=false)
Curvature drive inverse kinematics for differential drive robots. The rotation parameter controls the...
Definition DifferentialDrive.hpp:170
Here is the call graph for this function:

◆ TEST_F() [6/6]

TEST_F ( DifferentialDriveTests ,
CurvatureDriveSquareInputs  )

Test DifferentialDrive CurvatureDrive with square inputs.

Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2025-03-04
220{
221 // Create array for storing input and expect output values.
222 const int nTestValuesLength = 11;
223 const double aSpeedInput[nTestValuesLength] = {-1.0, -0.5, 0.0, 0.5, 1.0, 0.0, 0.0, 0.0, 0.0, 0.3, 1.5};
224 const double aRotationInput[nTestValuesLength] = {0.0, 0.0, 0.0, 0.0, 0.0, -1.0, -0.5, 0.5, 1.0, 1.0, 1.5};
225 const bool aAllowTurnInPlaceInput[nTestValuesLength] = {true, true, true, true, true, true, true, true, true, true, true};
226 const double aLeftSpeedOutput[nTestValuesLength] = {-1.0, -0.25, 0.0, 0.25, 1.0, -1.0, -0.25, 0.25, 1.0, 0.18, 1.0};
227 const double aRightSpeedOutput[nTestValuesLength] = {-1.0, -0.25, 0.0, 0.25, 1.0, 1.0, 0.25, -0.25, -1.0, 0.0, 0.0};
228
229 // Loop through each value and compare inputs and outputs.
230 for (int nIter = 0; nIter < nTestValuesLength; ++nIter)
231 {
232 // Calculate drive powers.
233 diffdrive::DrivePowers stDriveOutput = diffdrive::CalculateCurvatureDrive(aSpeedInput[nIter], aRotationInput[nIter], aAllowTurnInPlaceInput[nIter], true);
234
235 // Check that the expected output values were calculated.
236 EXPECT_NEAR(aLeftSpeedOutput[nIter], stDriveOutput.dLeftDrivePower, 0.02); // Left output check.
237 EXPECT_NEAR(aRightSpeedOutput[nIter], stDriveOutput.dRightDrivePower, 0.02); // Right output check.
238 }
239}
Here is the call graph for this function: