56 vex::wait(5, vex::msec);
81 posChange = posChange + trackerTravel;
87 vex::wait(20, vex::msec);
96 int dir = std::abs(target)/target;
100 while ((targetRot - pos) * dir > 0)
138 int dir = double(std::abs(target) / target);
177 int errorSign = std::abs(error)/error;
179 while (!(std::abs(error.
degrees()) < 10) || errorSign == std::abs(error)/error)
185 if((std::abs(error.
degrees()) < 5)){
190 errorSign = std::abs(error)/error;
223 m_rotation = std::make_shared<vex::rotation>(rotation);
226 m_rotation = std::make_shared<vex::rotation>(rotation);
229 Angle currentAngle =
Degrees(m_rotation->position(vex::degrees));
231 m_travelAngle =
Angle(currentAngle - m_lastAngle);
232 m_lastAngle = currentAngle;
236 return m_travelDistance;
Header containing the SmartDrive class.
A Utility Unit class for Angles.
double revolutions()
Returns the Angle in revolutions.
double degrees()
Returns the Angle in degrees.
A Utility Unit class for Length.
double calculate(double error)
Runs the PID by providing an input, then calculates and returns an output.
bool isCompleted()
Gets the current state of the PID.
void reset()
Resets the PID object.
void turnForPID(Angle target)
Turns for a specified angle (and stops)
void turnToPID(Angle target)
Turns tp a specified angle (and stops)
SmartDrive & withTurnForPID(PID pid)
Sets the PID object for the turnForPID Method.
Angle m_LastLeftPos
The last angle read from the Left motors.
Angle m_dir
Stores the current heading of the robot.
PID m_driveForPID
The PID object for the driveFor Method.
HorizontalTracker m_tracker
Stores the Horizontal Tracker.
Angle getRightTravel()
Gets the Angle traveled by the left motors.
SmartDrive & withTurnToPID(PID pid)
Sets the PID object for the turnToPID Method.
Vec2 m_pos
Stores the Position of the robot.
double m_gearRatio
A double representing the gear ratio of the drivetrain.
SmartDrive(TankDrive drive, vex::inertial inert)
Construct a new Smart Drive object.
Angle getLeftTravel()
Gets the Angle traveled by the left motors.
Angle m_LastRightPos
The last angle read from the Right motors.
Length getWheelTravel()
Get the Travel of the wheels for one revolution of the motor.
SmartDrive & withGearRatio(double ratio)
Sets the gear ratio of the drivetrain.
SmartDrive & withWheelSize(Length size)
Sets the wheel size of the Smart Drive.
int track()
Continuously tracks and updates the position of the SmartDrive.
vex::inertial m_inert
Stores the inertial sensor object.
Length m_wheelSize
A Length representing the diameter of the wheel.
PID m_turnForPID
The PID object for the turnForPID Method.
SmartDrive & withHorizontalTracker(vex::rotation rotation, Length wheelSize, double gearRatio)
Add Horizontal Tracker to the SmartDrive.
Vec2 m_centerPos
Stores the Center Position of the robot.
void turnFor(Angle target, double speed)
Turns for a specified Angle.
SmartDrive & withDriveForPID(PID pid)
Sets the PID object for the driveForPID Method.
PID m_turnToPID
The PID object for the turnToPID Method.
void turnTo(Angle target, double speed)
Turns to a specified field-centric Angle.
void driveFor(Length target, double speed)
Drives for a specified distance.
void driveForPID(Length target)
Drives for a specified distance (and stops)
A Simple TankDrive class.
SimpleMotorGroup m_left
a SimpleMotorGroup for the left side
void arcade(double x, double y, double rot)
Commands the TankDrive using arcade inputs.
SimpleMotorGroup m_right
a SimpleMotorGroup for the right side
Angle Degrees(double degrees)
Constructs an Angle from Degrees.
Angle shortestTurnPath(const Angle target)
Returns the shortest turn path to reach the target angle.
Angle Revolutions(double revolutions)
Constructs an Angle from Revolutions.
A struct for tracking the robot's lateral displacement.
HorizontalTracker()
Construct an empty Horizontal Tracker object.
Length getTravel()
Get the distance traveled by the Horizontal Tracker.
Length m_offset
Stores a Length representing the vertical distance from horizontal tracker to the tracking center (po...
std::shared_ptr< vex::rotation > m_rotation
A Pointer to a rotation sensor object.
A Utility 2D Vector class.
static Vec2 dirAndMag(double dir, double mag)
Constructs a vector with the specified direction and magnitude.