HoloLib
High-performance holonomic (X-Drive) control library for VEX V5
Loading...
Searching...
No Matches
chassis.hpp
Go to the documentation of this file.
1#pragma once
5#include "pros/imu.hpp"
6#include "pros/motors.hpp"
7
8#define chassisAsync(f) hololib::motion_handler::move([&] { f; });
9
10namespace hololib {
11
12class Chassis {
13public:
14 Chassis(pros::Motor& frontLeft,
15 pros::Motor& frontRight,
16 pros::Motor& backLeft,
17 pros::Motor& backRight,
18 pros::IMU& imu,
21 imu(imu), odom(odom), headingPID(PID{0, 0, 0, 0}), settled(Timer{0}), targetHeading(0.0f),
22 headingInitialized(false), receivedRotateInput(false), MAX_DRIVE_INPUT(127.0f),
23 SETTLE_DELAY_MS(150), MAX_CORRECTION(40.0f) {};
24
25 /**
26 * @brief Represents a simple deadzone-minimum output exponential or linear
27 * drive curve.
28 */
29 struct DriveCurve {
30 float curve_multipler = 1.0f; /**< Curvature scale */
31 float deadzone = 0.0f; /**< Deadzone before response begins */
32 float minimum_output = 0.0f; /**< Minimum voltage output once deadzone is surpassed */
33 };
34
35 /**
36 * @brief Holds the drive curves for movement and rotation inputs.
37 */
38 struct DriveCurves {
39 DriveCurve movement; /**< Curve mapping for forward/sideways translation */
40 DriveCurve rotation; /**< Curve mapping for rotational input */
41 };
42
43 /**
44 * @brief Configuration for active heading correction during driver control.
45 */
47 bool correctionOn = true; /**< True to actively maintain heading when
48 rotation joystick is released */
49 float kP = 1.0f; /**< Proportional gain for heading hold */
50 float kI = 0.01f; /**< Integral gain for heading hold */
51 float kD = 0.1f; /**< Derivative gain for heading hold */
52 };
53 void calibrate();
54
55 void drive(float vx, float vy, float omega, float theta);
56
57 void driveControl(float forward,
58 float sideways,
59 float rotation,
60 DriveCurves drivecurves,
61 bool fieldCentric,
62 float headingOffset,
63 DriveCorrection correction);
64
65 void brake();
66
68
69private:
70 pros::Motor& frontLeft;
71 pros::Motor& frontRight;
72 pros::Motor& backLeft;
73 pros::Motor& backRight;
74 pros::IMU& imu;
75
77
78 // Driver control global variables
79 const float MAX_DRIVE_INPUT;
80 const uint32_t SETTLE_DELAY_MS;
81 const float MAX_CORRECTION;
82 static constexpr float JOYSTICK_SCALING_FACTOR = 12000.0f / 127.0f; // Scale joystick input to motor voltage range
83 PID headingPID;
84 Timer settled;
85 float targetHeading;
86 bool headingInitialized;
87 bool receivedRotateInput;
88
89 // Collision detection variables
90 uint32_t last_collision_check_time = 0;
91 uint32_t stall_accumulator_ms = 0;
92};
93} // namespace hololib
A standard PID controller with advanced features.
Definition PID.hpp:22
void drive(float vx, float vy, float omega, float theta)
Chassis(pros::Motor &frontLeft, pros::Motor &frontRight, pros::Motor &backLeft, pros::Motor &backRight, pros::IMU &imu, EncoderEKFOdometry &odom)
Definition chassis.hpp:14
bool detectCollision()
void driveControl(float forward, float sideways, float rotation, DriveCurves drivecurves, bool fieldCentric, float headingOffset, DriveCorrection correction)
hololib::EncoderEKFOdometry odom
pros::Imu imu
pros::Motor frontRight
pros::Motor frontLeft
pros::Motor backLeft
pros::Motor backRight
Configuration for active heading correction during driver control.
Definition chassis.hpp:46
float kD
Derivative gain for heading hold.
Definition chassis.hpp:51
float kI
Integral gain for heading hold.
Definition chassis.hpp:50
float kP
Proportional gain for heading hold.
Definition chassis.hpp:49
bool correctionOn
True to actively maintain heading when rotation joystick is released.
Definition chassis.hpp:47
Represents a simple deadzone-minimum output exponential or linear drive curve.
Definition chassis.hpp:29
float minimum_output
Minimum voltage output once deadzone is surpassed.
Definition chassis.hpp:32
float curve_multipler
Curvature scale.
Definition chassis.hpp:30
float deadzone
Deadzone before response begins.
Definition chassis.hpp:31
Holds the drive curves for movement and rotation inputs.
Definition chassis.hpp:38
DriveCurve rotation
Curve mapping for rotational input.
Definition chassis.hpp:40
DriveCurve movement
Curve mapping for forward/sideways translation.
Definition chassis.hpp:39