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);
}
}