Pros, code issue(Op control)

I have a program which moves the robot, with some macros, however only the Y axis for the right is detected, which is weird because only the X axis was programmed for the right, nothing else works other than 2 motors for both Y axes, despite the right Y never being put the program. When I move it sideways nothing happens. Thanks

#include "main.h"

 void opcontrol() {
  pros::Controller master(pros::E_CONTROLLER_MASTER);
  pros::Motor left_mtr(1);
  pros::v5 upload --slot SLOT_2;
  pros::Motor right_mtr(10,1);
  pros::Motor left_mtr2(9,1);
  pros::Motor right_mtr2(2);
  pros::Motor tray2(5);
  pros::Motor intake_left(5);
  pros::Motor intake_right(3,1);
  pros::Motor tray(9);
  //left and right is viewed from back of robot
  while (true) {
 	 int left = master.get_analog(ANALOG_LEFT_Y);
 	 int right = master.get_analog(ANALOG_LEFT_X);
	 left_mtr.move_velocity((left) + (right));
	 left_mtr2.move_velocity((left) + (right));
 	 right_mtr.move_velocity((left) - (right));
 	 right_mtr2.move_velocity((left) - (right));
	//arcade control
    int tray_speed=127;
 	  if(master.get_digital(DIGITAL_R2)) {
 		   tray_speed -= 1;

 		 //deploying tray system at proportional speed, speed will decrease every 50 MS
 	  else if (master.get_digital(DIGITAL_R1)) {
 		 tray_speed = 127;
 		//moves tray back at 127 rpm

 	  else if(master.get_digital(DIGITAL_Y)){
 		 //moving tray back at partial speed
 	  else if(master.get_digital(DIGITAL_A)){
 		 //deploying tray system at partial speed to prevent cubes from tipping

 	 if (master.get_digital(DIGITAL_L1)) {
 		 //When L1 is pressed intake stops, or is revesed when L1 is held down
 	 else if (master.get_digital(DIGITAL_L2)) {
 		 //intake on/off switch

Was this a typo?

Did you consider range of values?

pros::Controller.get_analog() returns values [-127,127]

pros::Motor.move_velocity() takes values from ±100, ±200, or ±600 depending on the motor’s gearset

What happens if you do (left)+(right) ?

1 Like

yes but that’s for uploading it to a different slot, it seems to also not work without it, I later figured out how to upload to a different slot.

first of all

should not be in your code. Does your code compile with this line?

master.get_analog has value from -127 to 127

move_velocity have the value from -100 to 100 or -200 to 200 or -600 to 600 depending on your motor cartridge. You may want to use move function.

You may want to declare your variable outside of while loop. There is not need to repeatedly declare them.


That’s not how you upload to other slots…

That’s not even a valid line of code. How does this compile?

Your arcade code is not optimal. Also it is confusing to call the joystick values left and right. Y is the Velocity component and X is the Yaw component. So you need to get the skid steer velocity for left and right drive due to each of these components.

As @weilin said you need to scale so the max values are with in range. So consider the Speed Magnitude, mS, we want to remove the speed contribution due yaw from the velocity. For this we scale velocity by the percentage that is applied to yaw and divide by 2 (b/c Yaw can contribute to half the full velocity.) So mS looks like.
mS = V - (V*|Y|/127)/2
likewise we do the same for Yaw.
mY = Y - (Y*|V|/127)/2
Notice that when finding the %, absolute values are used.

Now we can find the Left and Right Velocities.
L = mS + mY
R = mS - mY

Maybe tonight, I’ll try to posting some tables showing output values so you can get a feel for how this works.