5#include "Eigen/Geometry"
18#include "pros/adi.hpp"
19#include "pros/rotation.hpp"
45 Chassis(pros::Motor fl, pros::Motor fr, pros::Motor bl, pros::Motor br,
81 void setPose(
float x,
float y,
float theta = 0.0f);
139 float headingOffset = 0.0f,
164 void followPath(
const std::vector<PathPoint> &path,
float lookahead_inches,
167 float holdAngleDeg = 0.0f,
bool reversed =
false);
196 bool angleCorrection =
true);
207 MoveParams params = defaultParams,
bool holdHeading =
true);
217 bool holdHeading =
true);
227 bool holdHeading =
true);
302 float thetaProcessNoise,
float measurementNoise);
327 void openLoop(
float forward,
float sideways,
float rotation);
430 template <
typename F>
432 bool fieldCentric =
true,
float headingOffset = 0.0f,
489 pros::Motor frontLeft, frontRight, backLeft, backRight;
490 std::vector<pros::Motor> motors{frontLeft, frontRight, backLeft, backRight};
496 Pose currentPose{0, 0, 0};
497 pros::Mutex poseMutex;
500 float prev_fl = 0, prev_fr = 0, prev_bl = 0, prev_br = 0;
501 float prev_heading = 0;
502 float targetHeadingDriveControl = 0;
504 float motionDistTraveled = 0.0f;
505 float xProcessNoise = 0.001f, yProcessNoise = 0.001f,
506 thetaProcessNoise = 0.003f, measurementNoise = 0.0001f;
507 bool velocityCalculationsOn =
false;
511 float avoidanceSafetyMargin = 4.0f;
512 float avoidanceClearance = 8.0f;
515 float pf_influence_radius = 15.0f;
519 uint32_t last_collision_check_time = 0;
520 uint32_t stall_accumulator_ms = 0;
522 std::vector<TrackingWheelConfig> trackingWheelConfigs;
523 std::vector<pros::Rotation> trackingWheelSensors;
524 std::vector<float> prevTrackingPositions;
525 bool useTrackingWheels =
false;
526 float trackingWheelMeasNoise = 0.0005f;
The main Chassis controller class.
void logReplayData(pros::Controller master, int timeout_ms=50)
Logs the driver's movements in real time to enable playback features.
Pose getPose(bool radians=false)
Get the current odometry pose of the robot.
friend void odomTaskTrampoline(void *)
float degToRad(float deg)
Utility: Convert Degrees to Radians.
void openLoop(float forward, float sideways, float rotation)
Apply direct open-loop power to the drivetrain without PID.
void addTrackingWheel(TrackingWheelConfig config)
Register a tracking wheel with the odometry module.
void waitUntil(float distance)
Wait until a certain linear distance has been covered during a motion command.
void odometryTask()
Infinite loop function typically passed to a background PROS task to update position continuously.
void setYGains(std::vector< ScheduledGain > steps)
Provide scheduled gains for the Y-axis translation controller.
void setVelocityCalculations(bool state)
Toggles whether to calculate velocities via odometry (computationally heavier).
void getControllerInput(pros::Controller master)
Reads inputs from the standard PROS controller into the drive control method.
void disableReplayDataLogging()
Stops driver motion logging.
void setRobotDimensionsAvoidance(float width, float height)
Set robot dimensions used specifically for avoidance calculations.
void curveCircle(float targetThetaDeg, float radius, MoveParams params=defaultParams, CurveDirection direction=CurveDirection::Auto)
Drive in a circular arc until reaching a specified heading.
void moveRelative(float forward, float sideways, MoveParams params=defaultParams, bool holdHeading=true)
Move a relative distance using X and Y offsets.
XDriveVoltages calculateHolonomic(float vx, float vy, float vt)
Calculate the individual motor voltages for a holonomic movement command.
MotionHandler motion
Background task handler instance.
void removeObstacle(size_t index)
Remove an obstacle by index.
void calibrate()
Calibrates sensors (e.g.
void brake()
Instructs all motors to brake using their configured brake mode.
void swingTurn(float targetThetaDeg, SwingSide lockedSide, MoveParams params=defaultParams)
Execute a swing turn where one side of the robot is held stationary.
void setXGains(std::vector< ScheduledGain > steps)
Provide scheduled gains for the X-axis translation controller.
void runDriverReplay(std::vector< PathPoint > data, float lookahead)
Playback previously recorded driver inputs autonomously.
void addObstacle(float x, float y, float radius)
Add an obstacle to the avoidance system.
float radToDeg(float rad)
Utility: Convert Radians to Degrees.
void setEKFGains(float xProcessNoise, float yProcessNoise, float thetaProcessNoise, float measurementNoise)
Set specific internal Extended Kalman Filter variables manually.
void setAvoidanceParams(float safetyMargin, float clearance)
Tunes the obstacle avoidance distance thresholds.
void clearTrackingWheels()
Unregisters all external tracking wheels.
Chassis(pros::Motor fl, pros::Motor fr, pros::Motor bl, pros::Motor br, pros::Imu imu_sensor, ChassisConfig config)
Construct a new Chassis object.
void moveDistance(float distance, MoveParams params={}, bool holdHeading=true)
Drive straight for a specified distance.
void setMotorVoltages(XDriveVoltages v)
Command the base motors with a set of voltages.
void cancelAllMotions()
Halts all running background motions in the motion handler queue.
void strafeDistance(float distance, MoveParams params=defaultParams, bool holdHeading=true)
Strafe for a specified distance.
void turnToPoint(float tx, float ty, MoveParams params=defaultParams)
Autonomously turn the robot to face a specific coordinate.
void cancelMotion()
Cancels the currently executing autonomous motion.
void setPose(Pose pose)
Reset the robot's odometry position to a Pose object.
void setPose(float x, float y, float theta=0.0f)
Manually reset the robot's odometry position.
void waitUntilDone()
Blocks the current thread until the current motion is finished.
SwingSide
Determines which side to lock during a swing turn.
void setEKFstate(bool state)
Toggle the internal EKF feature entirely.
void followPath(const std::vector< PathPoint > &path, float lookahead_inches, MoveParams params=defaultParams, HeadingMode headingMode=HeadingMode::FollowPath, float holdAngleDeg=0.0f, bool reversed=false)
Autonomously follow a path defined by points.
void driveControl(float forward, float sideways, float rotation, DriveCurves drivecurves, bool fieldCentric, float headingOffset=0.0f, DriveCorrection correction={})
Main driver control mapping logic.
void setMoveParams(MoveParams params)
Sets global default move parameters.
void setPotentialFieldParams(float ka, float kr, float influenceRadius)
Configures Artificial Potential Field parameters.
void clearObstacles()
Clears all current obstacles from memory.
void turnToHeading(float targetDeg, MoveParams params=defaultParams)
Autonomously turn the robot to face a specific heading.
AvoidanceMode
Status of the Obstacle Avoidance subsystem.
float getDistanceTraveled(bool convertToMeters=false)
Retrieves the total distance traveled during a motion segment.
void moveToPoint(float tx, float ty, MoveParams params=defaultParams, bool angleCorrection=true)
Autonomously drive directly to a coordinate on the field.
void move(F updateFunction, MoveParams params=defaultParams, bool fieldCentric=true, float headingOffset=0.0f, DriveCorrection correction={})
Generic templated loop to accept external calculation functions.
void setThetaGains(std::vector< ScheduledGain > steps)
Provide scheduled gains for the rotational (Theta) controller.
CurveDirection
Automatic, clockwise, or counter-clockwise rotation preference.
bool detectCollision()
Detect sudden impact indicating a potential collision using acceleration delta.
void setAvoidanceMode(AvoidanceMode mode)
Enables or disables the obstacle avoidance system globally.
void moveToPose(float tx, float ty, float targetThetaDeg, MoveParams params=defaultParams)
Move the robot to an exact X, Y, and Theta simultaneously.
Standard 1D Kalman filter for smoothing raw motor encoder values.
A scheduler that interpolates and selects PID gains based on the current error.
Manages the execution of motion commands asynchronously.
Manages a collection of obstacles and provides avoidance computations.
Extended Kalman Filter implementation for maintaining the robot's pose.
HeadingMode
Specifies the heading behavior during path following.
Core constants to configure the chassis dimensions and hardware.
Configuration for active heading correction during driver control.
Holds the drive curves for movement and rotation inputs.
Parameters defining bounds and conditions for autonomous movements.
Contains global coordinates and velocity.
Configuration parameters for a tracking wheel.
Holonomic target voltages for a 4-motor X-drive or mecanum base.