First I changed the names for the mechanisms to match the current robot setup. I then made a new header file for the mechansims and a new cpp file for the mechanisms. The mechanisms now work the same way a piston works by allowing you to call the functions and input all the different variables inline. I also had to comment out all the old rotation code because of the changed names and not actually useing them, for now i'm just going to keep all the code where it is so I can look back on it for the future.

This commit is contained in:
Carter committed 2026-11-04 16:59:34 -05:00
1 parent 24ee947fd5
commit 94f88d09d6
11 files changed
+370 -84

No files matched your search

+68 -23
View File
@@ -4,10 +4,10 @@
// Chassis constructor
ez::Drive chassis(
// These are your drive motors, the first motor is used for sensing!
{12, 14}, // Left Chassis Ports (negative port will reverse it!)
{-11, -13}, // Right Chassis Ports (negative port will reverse it!)
{-11, -12}, // Left Chassis Ports (negative port will reverse it!)
{13, 14}, // Right Chassis Ports (negative port will reverse it!)
21, // IMU Port
6, // IMU Port
3.25, // Wheel Diameter (Remember, 4" wheels without screw holes are actually 4.125!)
360.0); // Wheel RPM = cartridge * (motor gear / wheel gear)
@@ -16,22 +16,23 @@ ez::Drive chassis(
// - you should get positive values on the encoders going FORWARD and RIGHT
// - `2.75` is the wheel diameter
// - `4.0` is the distance from the center of the wheel to the center of the robot
ez::tracking_wheel horiz_tracker(8, 2.75, 4.0); // This tracking wheel is perpendicular to the drive wheels
// ez::tracking_wheel vert_tracker(9, 2.75, 4.0); // This tracking wheel is parallel to the drive wheels
ez::tracking_wheel horiz_tracker(16, 3.25, 4.0); // This tracking wheel is perpendicular to the drive wheels
ez::tracking_wheel vert_tracker(17, 3.25, 2.0); // This tracking wheel is parallel to the drive wheels
// Default Objects
Pneumatics pistonControl;
ArmMech armObj;
Mechanisms motorControl;
//ArmMech armObj;
// Lift constructor
LiftMech liftObj(
/*LiftMech liftObj(
{0, 63194, 94246, 139878}, 4);
// Wrist constructor
WristMech wristObj(
{0, -14529}, 2);
{0, -14529}, 2);*/
/**
* Runs initialization code. This occurs as soon as the program is started.
@@ -45,7 +46,7 @@ void initialize() {
pros::delay(500); // Stop the user from doing anything while legacy ports configure
armObj.set_state_values(
/*armObj.set_state_values(
{0, -5642},
{0, -22702},
{0, -19740},
@@ -60,25 +61,25 @@ void initialize() {
armRotation.reset_position();
liftRotation.reset_position();
wristRotation.reset_position();
wristRotation.reset_position();*/
pros::Task liftControlTasck([&]{
/*pros::Task liftControlTasck([&]{
while (true) {
armObj.arm_control();
liftObj.lift_control();
wristObj.wrist_control();
pros::delay(10);
}
});
});*/
// Look at your horizontal tracking wheel and decide if it's in front of the midline of your robot or behind it
// - change `back` to `front` if the tracking wheel is in front of the midline
// - ignore this if you aren't using a horizontal tracker
// chassis.odom_tracker_back_set(&horiz_tracker);
chassis.odom_tracker_front_set(&horiz_tracker);
// Look at your vertical tracking wheel and decide if it's to the left or right of the center of the robot
// - change `left` to `right` if the tracking wheel is to the right of the centerline
// - ignore this if you aren't using a vertical tracker
// chassis.odom_tracker_left_set(&vert_tracker);
chassis.odom_tracker_right_set(&vert_tracker);
// Configure your chassis controls
chassis.opcontrol_curve_buttons_toggle(true); // Enables modifying the controller curve with buttons on the joysticks
@@ -281,22 +282,64 @@ void ez_template_extras() {
void opcontrol() {
// This is preference to what you like to drive on
chassis.drive_brake_set(MOTOR_BRAKE_HOLD);
lift.set_brake_mode(MOTOR_BRAKE_HOLD);
claw.set_brake_mode(MOTOR_BRAKE_HOLD);
roller.set_brake_mode(MOTOR_BRAKE_HOLD);
while (true) {
// Gives you some extras to make EZ-Template ezier
ez_template_extras();
// Call custom drive functions here
pistonControl.control_piston(PistonsP::claw_piston, ControlPeriodP::driver,
ControllerP::slave, ButtonsP::arrow_buttons);
pistonControl.control_piston(PistonsP::PlaceHolderP, ControlPeriodP::driver,
ControllerP::master, ButtonsP::arrow_buttons);
motorControl.motor_control(ControlPeriodM::driver, ControllerM::master, ButtonsM::right_shoulder_buttons,
MotorGroups::lift_MG, 127, -127);
motorControl.motor_control(ControlPeriodM::driver, ControllerM::master, ButtonsM::left_shoulder_buttons,
MotorGroups::claw_M, -127, 127);
motorControl.motor_control(ControlPeriodM::driver, ControllerM::master, ButtonsM::Y_B_buttons,
MotorGroups::roller_M, 127, 0);
// Basic control scheme
/*arm.set_brake_mode(MOTOR_BRAKE_HOLD);
if (master.get_digital(DIGITAL_L1)) {
arm.move(90);
}
else if (master.get_digital(DIGITAL_L2)) {
arm.move(-90);
}
else {
arm.brake();
}
lift.set_brake_mode(MOTOR_BRAKE_HOLD);
if (master.get_digital(DIGITAL_R1)) {
lift.move(127);
}
else if (master.get_digital(DIGITAL_R2)) {
lift.move(-127);
}
else {
lift.brake();
}
wrist.set_brake_mode(MOTOR_BRAKE_HOLD);
if (master.get_digital(DIGITAL_A)) {
wrist.move(20);
}
else if (master.get_digital(DIGITAL_B)) {
wrist.move(-20);
}
else {
wrist.brake();
}
//armObj.arm_driver_control(ControllerR::master, ButtonsR::left_shoulder_buttons);
//liftObj.lift_driver_control(ControllerR::master, ButtonsR::right_shoulder_buttons);
armObj.arm_driver_control(ControllerR::slave, ButtonsR::left_shoulder_buttons);
liftObj.lift_driver_control(ControllerR::slave, ButtonsR::right_shoulder_buttons);
wristObj.wrist_driver_control(ControllerR::slave, ButtonsR::Y_B_buttons);
//wristObj.rotate_wrist(90);
//armObj.arm_driver_control(ControllerR::slave, ButtonsR::left_shoulder_buttons);
//liftObj.lift_driver_control(ControllerR::slave, ButtonsR::right_shoulder_buttons);
//wristObj.wrist_driver_control(ControllerR::slave, ButtonsR::Y_B_buttons);
//wristObj.rotate_wrist(90);*/
chassis.opcontrol_arcade_standard(ez::SPLIT); // Standard split arcade
// chassis.opcontrol_tank(); // Tank control
@@ -305,10 +348,12 @@ void opcontrol() {
// chassis.opcontrol_arcade_flipped(ez::SINGLE); // Flipped single arcade
// Terminal debugging
std::cout << "Arm rotation sensor value: " << "\033[31m" << armRotation.get_position() << " cdg" << "mm\033[0m" << std::endl;
/*std::cout << "Arm rotation sensor value: " << "\033[31m" << armRotation.get_position() << " cdg" << "mm\033[0m" << std::endl;
std::cout << "Lift rotation sensor value: " << "\033[32m" << liftRotation.get_position() << " cdg" << "mm\033[0m" << std::endl;
std::cout << "Wrist rotation sensor value: " << "\033[33m" << wristRotation.get_position() << " cdg" << "mm\033[0m" << std::endl;
std::cout << "Arm limit switch value: " << "\033[34m" << armReset.get_value() << "mm\033[0m" << std::endl;*/
///pros::delay(250);
pros::delay(ez::util::DELAY_TIME); // This is used for timer calculations! Keep this ez::util::DELAY_TIME
}
}