Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
Pto Code Ugh
Browse files Browse the repository at this point in the history
  • Loading branch information
MNRedPanda committed Apr 10, 2024
1 parent 4f94bfd commit ff34efd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
17 changes: 9 additions & 8 deletions include/globals.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,26 @@ inline lib::Logger logger;

inline pros::Controller controller(pros::E_CONTROLLER_MASTER);

inline sylib::Addrled led(22, -1, 20);
inline sylib::Addrled pto_led(22, 42, 20);

// Flaps
inline auto flaps_piston = std::make_shared<pros::ADIDigitalOut>('C');
inline lib::Flaps flaps(flaps_piston);

// PTO
inline pros::ADIAnalogOut ptoPiston('A');
inline pros::ADIAnalogOut ptoPistonTwo('B');
inline pros::ADIAnalogOut pto_piston('A');
inline pros::ADIAnalogOut pto_piston_two('B');

// Intake
inline auto intake_motor = std::make_shared<pros::Motor>(-15);
inline auto intake_motor = std::make_shared<pros::Motor>(-12);
inline lib::Intake intake(intake_motor);

// Drivetrain
// drive motors
inline pros::Motor lF(1, pros::E_MOTOR_GEAR_BLUE);
inline pros::Motor lM(2, pros::E_MOTOR_GEARSET_06);
inline pros::Motor lB(3, pros::E_MOTOR_GEARSET_06);

inline pros::Motor rF(-8, pros::E_MOTOR_GEARSET_06);
inline pros::Motor rM(-9, pros::E_MOTOR_GEARSET_06);
inline pros::Motor rB(-10, pros::E_MOTOR_GEARSET_06);
Expand Down Expand Up @@ -76,7 +77,7 @@ inline lemlib::OdomSensors sensors{
};

// linear motion controller
inline lemlib::ControllerSettings linearController(
inline lemlib::ControllerSettings linear_controller(
22, // proportional gain (kP)
0, // integral gain (kI)
10, // derivative gain (kD)
Expand All @@ -89,7 +90,7 @@ inline lemlib::ControllerSettings linearController(
);

// angular motion controller
inline lemlib::ControllerSettings angularController(
inline lemlib::ControllerSettings angular_controller(
2, // proportional gain (kP)
0, // integral gain (kI)
30, // derivative gain (kD)
Expand All @@ -102,5 +103,5 @@ inline lemlib::ControllerSettings angularController(
);

// create the chassis
inline lemlib::Chassis chassis(drivetrain, linearController, angularController,
sensors);
inline lemlib::Chassis chassis(drivetrain, linear_controller,
angular_controller, sensors);
4 changes: 1 addition & 3 deletions src/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,14 @@ void initialize() {

intake.start_task();
flaps.start_task();
ptoPistonTwo.set_value(1);
pto_piston_two.set_value(1);

#ifdef LOGGING
logger.start_task();
logger.set_rate(10);
logger.set_state(lib::LoggerMode::FirstInFirstOut);
#endif

led.gradient(0x8B3AFD, 0x7DFF29, 0, 0, false, true);
led.cycle(*led, 1);

/*
Expand Down
20 changes: 14 additions & 6 deletions src/opcontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
*/
void opcontrol() {
printf("opcontrol started\n");
bool pto_enabled = true;
bool drive_reversed = false;

bool is_drive_reversed = false;
while (true) {
// Intake Control
if (controller.get_digital(pros::E_CONTROLLER_DIGITAL_R1)) {
Expand All @@ -42,10 +43,17 @@ void opcontrol() {

// Hang control
if (controller.get_digital_new_press(pros::E_CONTROLLER_DIGITAL_B)) {
controller.rumble("...");
ptoPistonTwo.set_value(0);
controller.rumble(".");
pto_enabled = !pto_enabled;
}

if (pto_enabled == false) {

pto_piston_two.set_value(0);
pto_led.set_all(0x6AF844);
} else {
ptoPiston.set_value(1);
pto_piston_two.set_value(1);
pto_led.set_all(0xFF5632);
}

/*
Expand All @@ -59,13 +67,13 @@ void opcontrol() {
// Drivetrain control
if (controller.get_digital_new_press(pros::E_CONTROLLER_DIGITAL_A)) {
controller.rumble(".");
is_drive_reversed = !is_drive_reversed;
drive_reversed = !drive_reversed;
}

int left = controller.get_analog(pros::E_CONTROLLER_ANALOG_LEFT_Y);
int right = controller.get_analog(pros::E_CONTROLLER_ANALOG_RIGHT_Y);

if (is_drive_reversed) {
if (drive_reversed) {
chassis.tank(-right, -left, 10);
} else {
chassis.tank(left, right, 10);
Expand Down

0 comments on commit ff34efd

Please sign in to comment.