#include "main.h" #include "lemlib/api.hpp" #include "lemlib/logger/stdout.hpp" #include "pros/misc.h" // controller pros::Controller controller(pros::E_CONTROLLER_MASTER); // drive motors pros::Motor lF(-9, pros::E_MOTOR_GEARSET_06); // left front motor. port 8, reversed pros::Motor lM(-7, pros::E_MOTOR_GEARSET_06); // left middle motor. port 20, reversed pros::Motor lB(8, pros::E_MOTOR_GEARSET_06); // left back motor. port 19 pros::Motor rF(-4, pros::E_MOTOR_GEARSET_06); // right front motor. port 2 pros::Motor rM(12, pros::E_MOTOR_GEARSET_06); // right middle motor. port 11 pros::Motor rB(2, pros::E_MOTOR_GEARSET_06); // right back motor. port 13, reversed // motor groups pros::MotorGroup leftMotors({lF, lM, lB}); // left motor group pros::MotorGroup rightMotors({rF, rM, rB}); // right motor group // Inertial Sensor on port 11 pros::Imu imu(21); // tracking wheels //pros::Rotation horizontalEnc(4); // horizontal tracking wheel. 2.75" diameter, 3.7" offset, back of the robot; // drivetrain settings lemlib::Drivetrain drivetrain(&leftMotors, // left motor group &rightMotors, // right motor group 10, // 10 inch track width lemlib::Omniwheel::NEW_275, // using new 3.25" omnis 450, // drivetrain rpm is 360 2 // chase power is 2. If we had traction wheels, it would have been 8 ); // lateral motion controller lemlib::ControllerSettings linearController(10, // proportional gain (kP) 30, // derivative gain (kD) 1, // small error range, in inches 100, // small error range timeout, in milliseconds 3, // large error range, in inches 500, // large error range timeout, in milliseconds 20 // maximum acceleration (slew) ); // angular motion controller lemlib::ControllerSettings angularController(2, // proportional gain (kP) 10, // derivative gain (kD) 1, // small error range, in degrees 100, // small error range timeout, in milliseconds 3, // large error range, in degrees 500, // large error range timeout, in milliseconds 20 // maximum acceleration (slew) ); // sensors for odometry // note that in this example we use internal motor encoders, so we don't pass vertical tracking wheels lemlib::OdomSensors sensors(nullptr, // vertical tracking wheel 1, set to nullptr as we don't have one nullptr, // vertical tracking wheel 2, set to nullptr as we don't have one nullptr, // horizontal tracking wheel 1 nullptr, // horizontal tracking wheel 2, set to nullptr as we don't have a second one &imu // inertial sensor ); // create the chassis lemlib::Chassis chassis(drivetrain, linearController, angularController, sensors); /** * Runs initialization code. This occurs as soon as the program is started. * * All other competition modes are blocked by initialize; it is recommended * to keep execution time for this mode under a few seconds. */ void initialize() { pros::lcd::initialize(); // initialize brain screen chassis.calibrate(); // calibrate sensors // the default rate is 50. however, if you need to change the rate, you // can do the following. // lemlib::bufferedStdout().setRate(...); // If you use bluetooth or a wired connection, you will want to have a rate of 10ms // for more information on how the formatting for the loggers // works, refer to the fmtlib docs // thread to for brain screen and position logging pros::Task screenTask([&]() { lemlib::Pose pose(0, 0, 0); while (true) { // print robot location to the brain screen pros::lcd::print(0, "X: %f", chassis.getPose().x); // x pros::lcd::print(1, "Y: %f", chassis.getPose().y); // y pros::lcd::print(2, "Theta: %f", chassis.getPose().theta); // heading // log position telemetry lemlib::telemetrySink()->info("Chassis pose: {}", chassis.getPose()); // delay to save resources pros::delay(50); } }); } /** * Runs while the robot is disabled */ void disabled() {} /** * runs after initialize if the robot is connected to field control */ void competition_initialize() {} // get a path used for pure pursuit // this needs to be put outside a function ASSET(example_txt); // '.' replaced with "_" to make c++ happy ASSET(testingpath_txt); /** * Runs during auto * * This is an example autonomous routine which demonstrates a lot of the features LemLib has to offer */ void autonomous() { chassis.setPose(9.72, -59.062, 90, false); chassis.follow(testingpath_txt, 15, 4000); chassis.waitUntilDone(); pros::lcd::print(4, "pure pursuit finished!"); // chassis.moveTo(20, 15, 90, 4000); // chassis.turnTo(45, -45, 1000, true, 60); // chassis.follow(example_txt, 15, 4000, false); // chassis.waitUntil(10); // pros::lcd::print(4, "Travelled 10 inches during pure pursuit!"); // chassis.waitUntilDone(); // pros::lcd::print(4, "pure pursuit finished!"); } /** * Runs in driver control */ void opcontrol() { // controller // loop to continuously update motors while (true) { // get joystick positions int leftY = controller.get_analog(pros::E_CONTROLLER_ANALOG_LEFT_Y); int rightX = controller.get_analog(pros::E_CONTROLLER_ANALOG_RIGHT_X); // move the chassis with curvature drive chassis.curvature(leftY, rightX); // delay to save resources pros::delay(10); } }