Pros V5 Mechana wheels Problem!

Need help strafing. Im not sure if I have the + and - wrong or if im using a completely different command but I need help with adding strafing to the controls


#include "main.h"
#define R 20
#define L 11
#define R2 19
#define L2 12


pros::Controller controller1(pros::E_CONTROLLER_MASTER);
pros:: Motor frontRight(20);
pros:: Motor frontLeft(11);
pros:: Motor backRight(19);
pros:: Motor backLeft(12);


 int JoystickAxis1(){
   int toReturn = controller1.get_analog(pros::E_CONTROLLER_ANALOG_RIGHT_X);
   return toReturn;
 }

 int JoystickAxis2(){
   int toReturn = controller1.get_analog(pros::E_CONTROLLER_ANALOG_RIGHT_Y);
   return toReturn;
 }

 int JoystickAxis3(){
   int toReturn = controller1.get_analog(pros::E_CONTROLLER_ANALOG_LEFT_Y);
   return toReturn;
 }

 int JoystickAxis4(){
   int toReturn = controller1.get_analog(pros::E_CONTROLLER_ANALOG_LEFT_X);
   return toReturn;
}


void drive_straight(int straight_ticks, int speed) {
frontLeft.move_relative(straight_ticks, speed);
backLeft.move_relative(straight_ticks, speed);
frontRight.move_relative(straight_ticks, speed);
backRight.move_relative(straight_ticks, speed);
}


/*void on_center_button() {
	static bool pressed = false;
	pressed = !pressed;
	if (pressed) {
		pros::lcd::set_text(2, "I was pressed!");
	} else {
		pros::lcd::clear_line(2);
	}
}

void auton() {
	if(controller1.get_digital(DIGITAL_A)){
	       autonomous();
	}
}

/**

############### Example autonomous #####################

void drive_straight(int straight_ticks, int speed) {
left_front_wheels.move_relative(straight_ticks, speed);
left_center_wheels.move_relative(straight_ticks,speed);
left_back_wheels.move_relative(straight_ticks, speed);
right_front_wheels.move_relative(straight_ticks, speed);
right_center_wheels.move_relative(straight_ticks, speed);
right_back_wheels.move_relative(straight_ticks, speed);
}

void autonomous() {
          drive_straight(1000,100);
}




################### Example #2 ##################

void auton() {
if(master.get_digital(DIGITAL_A)){
       autonomous();
}
}
 
void initialize() {
	pros::lcd::initialize();
	pros::lcd::set_text(1, "Scar Is here!!!!");

	pros::lcd::register_btn1_cb(on_center_button);
} */
/**
 * Runs while the robot is in the disabled state of Field Management System or
 * the VEX Competition Switch, following either autonomous or opcontrol. When
 * the robot is enabled, this task will exit.
 */
void disabled() {}

/**
 * Runs after initialize(), and before autonomous when connected to the Field
 * Management System or the VEX Competition Switch. This is intended for
 * competition-specific initialization routines, such as an autonomous selector
 * on the LCD.
 *
 * This task will exit when the robot is enabled and autonomous or opcontrol
 * starts.
 */
void competition_initialize() {}




 /**

 AUTONOMOIUS EXAMPLE! Chassis

 using namespace okapi;

const int DRIVE_MOTOR_LEFT = 1;
const int DRIVE_MOTOR_RIGHT = 2;

auto chassis = ChassisControllerFactory::create(DRIVE_MOTOR_LEFT, DRIVE_MOTOR_RIGHT);

void autonomous() {
  // Move to first goal
  chassis.moveDistance(1000);
  // Turn to face second goal
  chassis.turnAngle(100);
  // Drive toward second goal
  chassis.moveDistance(1500);
}

*/

void autonomous() {

  drive_straight(1000,100);

}

/**
 * Runs the operator control code. This function will be started in its own task
 * with the default priority and stack size whenever the robot is enabled via
 * the Field Management System or the VEX Competition Switch in the operator
 * control mode.
 *
 * If no competition control is connected, this function will run immediately
 * following initialize().
 *
 * If the robot is disabled or communications is lost, the
 * operator control task will be stopped. Re-enabling the robot will restart the
 * task, not resume it from where it left off.
 */



void opcontrol() {

/**

Arm Example! :)

ControllerButton btnUp(E_CONTROLLER_DIGITAL_R1);
ControllerButton btnDown(E_CONTROLLER_DIGITAL_R2);
Motor lift(LIFT_MOTOR);

void opcontrol() {
  while (true) {
    if (btnUp.isPressed()) {
      lift.moveVoltage(12000);
    } else if (btnDown.isPressed()) {
      lift.moveVoltage(-12000);
    } else {
      lift.moveVoltage(0);
    }
	*/

	while (true) {


		//int left = controller1.get_analog(ANALOG_LEFT_Y);
	//	int right = controller1.get_analog(ANALOG_RIGHT_Y);
	frontLeft.move_velocity(JoystickAxis3() + JoystickAxis1() + JoystickAxis4()*2);
	frontRight.move_velocity(JoystickAxis3() - JoystickAxis1() - JoystickAxis4()*2);
	backLeft.move_velocity(JoystickAxis3() + JoystickAxis1() - JoystickAxis4()*2);
	backRight.move_velocity(JoystickAxis3() - JoystickAxis1() + JoystickAxis4()*2);

	if(controller1.get_digital(pros::E_CONTROLLER_DIGITAL_X)){
		autonomous();
	}

		pros::delay(20);

	}
}

Not sure what type of drive you are going for but assuming you are making arcade drive code, why do you need the *2 at the end?

Here is an example program for making motors move using the controllers

#define MOTOR_PORT 1
void opcontrol() {
      while (true) {
          motor_move(MOTOR_PORT, controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y));
          delay(2);
      }
}
2 Likes

There is nothing wrong with your program, you are using the proper syntax/api.
You simply need to break down each component of the motor command and test it on its own.

First of all, make sure it can drive forward properly.
Apply positive power to all your motors and reverse the motor constructors until your robot drives straight.
Then, your motors will end up looking something like this (just guessing):

pros:: Motor frontRight(20, true);
pros:: Motor frontLeft(11);
pros:: Motor backRight(19, true);
pros:: Motor backLeft(12);

Then, introduce the turning (by applying positive power to the left and negative to the right), and make sure that the motor ports are correct and refer to the proper sides.

Finally, introduce strafing, by applying positive power to your front left and back right motors, and negative power to your front right and back left motors.

By this point, you should have all your motor ports and reversing properly configured, and it should work as expected.

Looking at your math, it seems like your addition of the components is done properly. Your problem is probably that half of your motors should be reversed, since they are on the opposite side of the drivetrain.

Btw, you are using move_velocity, which accepts a range of ±200, but the joysticks return a range of ±127. To be able to move at maximum power, you should either scale your values up, or you should use voltage control move which accepts ±127.

4 Likes