PROS OpControl Help

Hello, I need help with some code I just wrote. I’m a pretty terrible programmer overall, but I am also working alone this year so I need to be able to learn to program. I was initially trying to make a split arcade drive (like I have working in VexCode V5 Text) in PROS. Seeing as that failed, I simplified in hopes of making SOMETHING work, but no luck even with what is basically the example code. Here’s what I have for Split Arcade:

#include <math.h>

#define LF_PORT 12
#define LB_PORT 14

#define RF_PORT 17
#define RB_PORT 19

pros::Motor LFM (LF_PORT);
pros::Motor LBM (LB_PORT);
pros::Motor RFM (RF_PORT, true);
pros::Motor RBM (RB_PORT, true);

int LFM_Pow = 0;
int LBM_Pow = 0;
int RFM_Pow = 0;
int RBM_Pow = 0;

pros::Controller master (pros::E_CONTROLLER_MASTER);

Here’s the opcontrol:

void opcontrol() {
//simply the driver control portion

  while (true)
  {
    
    LFM_Pow = ((pow((master.get_analog(pros::E_CONTROLLER_ANALOG_LEFT_Y) + master.get_analog(pros::E_CONTROLLER_ANALOG_RIGHT_X)/1.5),3)) /(pow(100,2)));
    LBM_Pow = ((pow((master.get_analog(pros::E_CONTROLLER_ANALOG_LEFT_Y) + master.get_analog(pros::E_CONTROLLER_ANALOG_RIGHT_X)/1.5),3)) /(pow(100,2)));
    RFM_Pow = ((pow((master.get_analog(pros::E_CONTROLLER_ANALOG_LEFT_Y) - master.get_analog(pros::E_CONTROLLER_ANALOG_RIGHT_X)/1.5),3)) /(pow(100,2)));
    RBM_Pow = ((pow((master.get_analog(pros::E_CONTROLLER_ANALOG_LEFT_Y) - master.get_analog(pros::E_CONTROLLER_ANALOG_RIGHT_X)/1.5),3)) /(pow(100,2)));

    LFM.move(LFM_Pow);
    LBM.move(LBM_Pow);
    RFM.move(RFM_Pow);
    RBM.move(RBM_Pow);


LFM.move(master.get_analog(pros::E_CONTROLLER_ANALOG_LEFT_Y));
     pros::delay(2);
  }

}

Please help, I’d really like to be able to combine this code with other PROS code I wrote so I can actually utilize this.

I think the problem is that you are declaring *_Pow variables as ints and then trying to store there floating point values that could be <1.

Try to declare those as “double” not “int” and then print the values with printf for debugging.

https://pros.cs.purdue.edu/v5/tutorials/general/debugging.html

https://pros.cs.purdue.edu/v5/search.html?q=printf&check_keywords=yes&area=default

1 Like

Thank you Weilin. I’ll test. Also worth noting it may be the Move command I used which seems to take values between -127 and 127. Not sure if those motor power variables I had are going way higher or not. I just tried to mimic the code I had in VexCode…

Controller.get_analog() returns the same -127,127 range that is acceptable to pass into motor.move()

https://pros.cs.purdue.edu/v5/api/cpp/misc.html#get-analog
https://pros.cs.purdue.edu/v5/api/cpp/motors.html#move

I did notice that yes. However, I’m trying to basically convert my working code from Vexcode over, so that’s why I have the powers for the motors calculated the way I do. What function would you suggest using for that purpose? In VexCode I was using the spin command with velocity as a percent.

Also, I tried just doing printf(“testing”); in my while loop, when I turn on the program all I get is a gray screen. Not sure if this is some stupid LVGL thing plaguing me (I do have a working auton menu, I don’t know how it interacts with Opcontrol).

Oh–

and as a proof of concept to show that something seems to be really messed up, it still doesn’t work even when simplified this much:

void opcontrol() {
//simply the driver control portion

  while (true)
  {
/*
    LFM_Pow = ((pow((master.get_analog(pros::E_CONTROLLER_ANALOG_LEFT_Y) + master.get_analog(pros::E_CONTROLLER_ANALOG_RIGHT_X)/1.5),3)) /(pow(100,2)));
    LBM_Pow = ((pow((master.get_analog(pros::E_CONTROLLER_ANALOG_LEFT_Y) + master.get_analog(pros::E_CONTROLLER_ANALOG_RIGHT_X)/1.5),3)) /(pow(100,2)));
    RFM_Pow = ((pow((master.get_analog(pros::E_CONTROLLER_ANALOG_LEFT_Y) - master.get_analog(pros::E_CONTROLLER_ANALOG_RIGHT_X)/1.5),3)) /(pow(100,2)));
    RBM_Pow = ((pow((master.get_analog(pros::E_CONTROLLER_ANALOG_LEFT_Y) - master.get_analog(pros::E_CONTROLLER_ANALOG_RIGHT_X)/1.5),3)) /(pow(100,2)));

    LFM.move(LFM_Pow);
    LBM.move(LBM_Pow);
    RFM.move(RFM_Pow);
    RBM.move(RBM_Pow);
    printf("testing");
*/

LFM.move(master.get_analog(pros::E_CONTROLLER_ANALOG_LEFT_Y));
LBM.move(master.get_analog(pros::E_CONTROLLER_ANALOG_LEFT_Y));
RFM.move(master.get_analog(pros::E_CONTROLLER_ANALOG_RIGHT_Y));
RBM.move(master.get_analog(pros::E_CONTROLLER_ANALOG_RIGHT_Y));

     pros::delay(2);
  }

}

I’m not sure what else I can do. The definitions at the top are still the same. All I’m doing is entering the program from the menu normally. No competition switch or anything. Assuming this enters the Opcontrol function, I’m not sure what else to try.

Can you explain exactly what the problem is? Does the program not run, or does the robot not move when the program is run?

As far as I know, printf() doesn’t print to the brain screen, and I’m pretty sure that the grey screen is just the default LVGL output (assuming you removed LLEMU)

1 Like

Thanks. That must be the gray screen. I’m not using LLEMU.

The robot does not move when the program is run. Nothing happens. Not sure what could possibly be wrong. I may try putting the code in a new project.

PROS printf output goes not to the V5 brain screen but to the terminal window of the connected computer by design. This tutorial talks about how to work with it:

https://pros.cs.purdue.edu/v5/tutorials/general/debugging.html

LVGL is the method to use v5 display with PROS, but it takes some learning.

https://pros.cs.purdue.edu/v5/tutorials/topical/display.html

Also, you can try to get one of the PROS clawbot tutorials that is known to work as the starting point for your program.

If all else fails, you could switch from PROS to VEXcode Pro, which has a convenience functions to print on V5 screen and a number of builtin sample programs.

1 Like

Thanks, that would explain it. I looked into the printf a bit but I didn’t realize it went to the terminal. I was basically using the clawbot tutorial by the end of my testing (as in it was that simple) so I’ll have to keep fiddling with it until I get something working I guess.

As much as going back to VexCode is an option, I potentially wanted to use Okapi for odometry (provided I get meaningful access to a field this season to do auton) and I already have that auton menu which I really want to be able to implement. So, that would be worst case scenario…

Okay, problem solved. Literally all that was happening is my code was not downloading. I had been hitting the upload button, which is apparently not valid. Turns out you have to go save and then potentially the only button that can be used is the PROS Quick Action one. I figured out the terminal stuff, so thanks for that @weilin. Anyway that clears up all my issues for now, I might pm you if I run into any more later on.

3 Likes