So I’ve basically copied the code from the okapi tutorial but it always says there’s an error.

I was wondering if anyone else has experienced these errors before and know how to solve them.
So I’ve basically copied the code from the okapi tutorial but it always says there’s an error.
I was wondering if anyone else has experienced these errors before and know how to solve them.
I’ve seen codes that have an error in pros but still work if downloaded. Have u tried?
Nope, we don’t have access to our robot right now. But I’ll try once we do!
It looks right. What’s the error message? Did you run a make all?
Yeah, sometimes it says there are errors, but it compiles just fine. You can do that without a robot. Just click PROS<build<all.
Can you show the definition for driveLeftBack
and the other motors?
Is autonomous and chassis definition in different files? If so does the chassis definition (in a cpp) match the declaration (in a hpp)?
If they are in the same file then maybe auto
would work instead of directly specifying the Odom type.
You have an X-Drive, right?
btw. I see both type usage parsing correctly;
ed: line number to show no errors. and here’s the code …
std::shared_ptr<okapi::OdomChassisController> xchassis = okapi::ChassisControllerBuilder()
.withMotors(LEFT_DRIVE_MOTOR1_PORT,LEFT_DRIVE_MOTOR2_PORT,RIGHT_DRIVE_MOTOR1_PORT,RIGHT_DRIVE_MOTOR2_PORT)
.withDimensions(DRIVE_GEARSET,{{CHASSIS_WHEELS, CHASSIS_TRACK}, DRIVE_TPR})
.withGains({0.001,0.0,0.0001},{0.001,0.0,0.0001},{0.001,0.0,0.0001})
.withSensors(okapi::ADIEncoder{'A','B'},okapi::ADIEncoder{'C','D',true},okapi::ADIEncoder{'E','F'})
.withLogger(std::make_shared<okapi::Logger>(
okapi::TimeUtilFactory::createDefault().getTimer(), // It needs a Timer
"/ser/sout", // Output to the PROS terminal
okapi::Logger::LogLevel::info // Show errors, warnings, and info
)
)
.withOdometry()
.buildOdometry();
auto xchassis2 = okapi::ChassisControllerBuilder()
.withMotors(LEFT_DRIVE_MOTOR1_PORT,LEFT_DRIVE_MOTOR2_PORT,RIGHT_DRIVE_MOTOR1_PORT,RIGHT_DRIVE_MOTOR2_PORT)
.withDimensions(DRIVE_GEARSET,{{CHASSIS_WHEELS, CHASSIS_TRACK}, DRIVE_TPR})
.withGains({0.001,0.0,0.0001},{0.001,0.0,0.0001},{0.001,0.0,0.0001})
.withSensors(okapi::ADIEncoder{'A','B'},okapi::ADIEncoder{'C','D',true},okapi::ADIEncoder{'E','F'})
.withLogger(std::make_shared<okapi::Logger>(
okapi::TimeUtilFactory::createDefault().getTimer(), // It needs a Timer
"/ser/sout", // Output to the PROS terminal
okapi::Logger::LogLevel::info // Show errors, warnings, and info
)
)
.withOdometry()
.buildOdometry();
pros::Motor driveLeftFront(1, pros::E_MOTOR_GEARSET_18, false, pros::E_MOTOR_ENCODER_COUNTS);
pros::Motor driveLeftBack(2, pros::E_MOTOR_GEARSET_18, false, pros::E_MOTOR_ENCODER_COUNTS);
pros::Motor driveRightFront(9, pros::E_MOTOR_GEARSET_18, true, pros::E_MOTOR_ENCODER_COUNTS);
pros::Motor driveRightBack(10, pros::E_MOTOR_GEARSET_18, true, pros::E_MOTOR_ENCODER_COUNTS);
Thanks for the help!
std::shared_ptr<OdomChassisController> chassis =
ChassisControllerBuilder()
.withMotors(driveLeftBack, driveLeftFront, driveRightBack, driveRightFront)
.withGains(
{0.001, 0, 0.0001}, // distance controller gains
{0.001, 0, 0.0001}, // turn controller gains
{0.001, 0, 0.0001} // angle controller gains (helps drive straight)
)
.withSensors(
ADIEncoder{'A', 'B'}, // left encoder in ADI ports A & B
ADIEncoder{'C', 'D'}, true}, // right encoder in ADI ports C & D (reversed)
ADIEncoder{'E', 'F'} // middle encoder in ADI ports E & F
)
// green gearset, tracking wheel diameter (2.75 in), track (7 in), and TPR (360)
// 1 inch middle encoder distance, and 2.75 inch middle wheel diameter
.withDimensions(AbstractMotor::gearset::green, {{2.75_in, 7_in, 1_in, 2.75_in}, quadEncoderTPR})
.withOdometry() // use the same scales as the chassis (above)
.buildOdometry(); // build an odometry chassis
}
That’s what I thought.
You are passing pros motors to okapi, which requires okapi motors.
pros::Motor driveLeftFront(1, pros::E_MOTOR_GEARSET_18, false, pros::E_MOTOR_ENCODER_COUNTS);
so should I change it to this?
okapi::Motor driveLeftFront(1, okapi::E_MOTOR_GEARSET_18, false, okpai::E_MOTOR_ENCODER_COUNTS);
So .withMotors() only accepts numerical values, not actual motor objects. So instead of saying .withMotors(driveLeftFront, driveRightFront), which are both motor objects that you create when you declare them, just say .withMotors(1,2) where 1 and 2 are the ports those motors are plugged into.
According to which docs? You should read them, as that is incorrect: okapi::ChassisControllerBuilder class | OkapiLib A PROS library for programming VEX robots.
It accepts all sorts of motor objects, and it does not actually accept any numerical values. Instead, when you give it a number it implicitly converts the value into a motor object via the motor constructor.
However, your suggestion of passing the port numbers instead of the motor objects will work, as it will implicitly create the right kind of motor.
Read the documentation. You can either give your ports directly to withMotors
(recommended), or you can read the docs to find the correct way to construct an okapi motor.
Thanks! It now works. But when I try to use it in my auton, it says that the “chassis” is undefined.
void autonomous() {
chassis->setState ({0_in, 0_in, 0_deg});
chassis->driveToPoint ({1_ft, 1_ft});
}
Your have to define the chassis in a header file.
Don’t define it in a header file, that would cause linker errors. You don’t even need to declare it in a header file, as you aren’t using multiple files.
You just need to define the chassis to be in global scope, outside of the initialize
function where it currently lives, so that the other functions in the file can see it. You can either do that by moving the entire declaration and builder chain to be outside of initialize, or you can do as the tutorials say (recommended):
std::shared_ptr<OdomChassisController> chassis; // empty
void initialize() {
chassis = ChassisControllerBuilder()...build();
}