I use the PROS extension to program, and I have questions on how to get relative degrees rather than absolute positon.
In the opcontrol, I write these code
void opcontrol() {
master.clear();
int a = 0;
int Ch1, Ch2, Ch3, Ch4;
bool L1, L2, R1, R2, BtnA, BtnB, BtnX, BtnY, BtnU, BtnD, BtnL, BtnR;
while (true) {
//Controller value defination
Ch1 = master.get_analog(ANALOG_RIGHT_X);
Ch2 = master.get_analog(ANALOG_RIGHT_Y);
Ch3 = master.get_analog(ANALOG_LEFT_Y);
Ch4 = master.get_analog(ANALOG_LEFT_X);
L1 = master.get_digital(DIGITAL_L1);
L2 = master.get_digital(DIGITAL_L2);
R1 = master.get_digital(DIGITAL_R1);
R2 = master.get_digital(DIGITAL_R2);
BtnA = master.get_digital(DIGITAL_A);
BtnB = master.get_digital(DIGITAL_B);
BtnX = master.get_digital(DIGITAL_X);
BtnY = master.get_digital(DIGITAL_Y);
BtnU = master.get_digital(DIGITAL_UP);
BtnD = master.get_digital(DIGITAL_DOWN);
BtnL = master.get_digital(DIGITAL_LEFT);
BtnR = master.get_digital(DIGITAL_RIGHT);
pros::lcd::print(2,"%d",leftchassis.get_raw_position(NULL,2));
//Screen Display
pros::lcd::set_text(1,"Running Driver Control!");
pros::lcd::print(0, "%d %d %d", (pros::lcd::read_buttons() & LCD_BTN_LEFT) >> 2,
(pros::lcd::read_buttons() & LCD_BTN_CENTER) >> 1,
(pros::lcd::read_buttons() & LCD_BTN_RIGHT) >> 0); // Prints status of the emulated screen LCDs
//==================================================
if(abs(Ch1)>7 or abs(Ch3) > 7)
{
leftchassis.move(Ch3 - Ch1);
rightchassis.move(Ch3 + Ch1);
}
else
{
leftchassis.set_brake_mode(pros::motor_brake_mode_e_t::E_MOTOR_BRAKE_COAST);
rightchassis.set_brake_mode(pros::motor_brake_mode_e_t::E_MOTOR_BRAKE_COAST);
leftchassis.brake();
rightchassis.brake();
}
if(BtnY && a==0)
{
Mego.set_value(1);
WaitUntil(!master.get_digital(DIGITAL_Y));
a=1;
}
else if (master.get_digital(DIGITAL_Y) && a==1)
{
Mego.set_value(0);
WaitUntil(!master.get_digital(DIGITAL_Y));
a=0;
}
pros::delay(20); // Run for 20 ms then update
}
}
This code can retern and print the motor_group’s relative degrees , but it is not correct. For example, running the program, I let motor move, And it shows the relative degrees is 15757, but when I check the "Device " in the Brain, it shows the correct relative degrees is 18908. The difference in degrees is too large. Is there any solutions to solve this problem???