(Potential) Code for Arcade Drive at Full Speed


I couldn’t respond to the Tech Support Forum, so I created a thread here…

This is some code I wrote up in RobotC that might do what you want. I don’t have a robot available to test it with, but I don’t see anything wrong with it… :rolleyes:

Note: This was written for the PIC controller and old radio transmitters.

#pragma config(Motor,  port1,           leftMotor,     tmotorNormal, openLoop)
#pragma config(Motor,  port2,           rightMotor,    tmotorNormal, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//
//             Arcade Drive           //
//                                    //
// This code *should* be an arcade    //
// drive control that can drive up to //
// full speed.  This was made for the //
// "old" VEX system - PIC controller  //
// and radio control.                 //
//                                    //
//            -Andrew (RoboDesigners) //
//           Programmer for VRC #2190 //
//              [www.RoboDesigners.com](http://www.RoboDesigners.com) //
task main()
  //Define X and Y variables
  int joyX;
  int joyY;
  bIfiAutonomousMode = false; //Enable driver operation
    //Puts meaningful values in the X and Y variables
    joyX = vexRT[Ch1];
    joyY = vexRT[Ch2];
    if (joyY > 0) //If the joystick is right of the Y axis
      motor[leftMotor] = joyY; //Left motor power is directly tied to the Y axis
      /*This is the "hard" line - the right motor's power is a percent (found based
        on the X position of the joystick) of the Y axis */
      motor[rightMotor] = ((127 - joyX) / 127) * joyY;
      if (joyX < 0) //If the joystick is left of the Y axis
        //This block of code is the reverse of the above block
        motor[rightMotor] = joyY;
        motor[leftMotor] = ((127 + joyX) / 127) * joyY;
      else //If the joystick is centered in the Y axis
        //Both motors go same speed, tied to Y axis
        motor[leftMotor] = joyY;
        motor[rightMotor] = joyY;

There is no need for such long code. Simply deleting the “/2” will work. In new versions of robotc, values over 127 won’t cause an error. I programmed a holonomic drive last year, and had to work with a 3 axis system. If it was that complicated, my code would have been much much longer.

I agree that there is probably a more efficient way to write the code… I’m kind-of new to RobotC.

Where is the “/2”? In the “hard” line (not really that hard, but it is the largest line in the program), I turn the distance from the center of the joystick to a percent/decimal number, but I don’t divide by 2… :confused:

Oh, and something I forgot to add to the first post:

This was written with port 1 controlling the motors on the left of the robot, and port 2 controlling right-hand motors.

The “/2” is in the original vex wiki arcade drive code that chris_is_me was refering to.

:o oops…

That code seems overly complicated. Here’s mine:

void ArcadeDrive(int Forwards, int Rotate)
// Forwards/Rotation
Motor1 = (Forwards + VexReceive(2)) + (Rotate + VexReceive(4));
Motor2 = (Forwards + VexReceive(2)) + (-Rotate + -VexReceive(4));

Motor1 and Motor2 can be replaced with the corresponding VEX RobotC motor function, and VexRecieve(x) can be replaced with VexRT[x]. It’s currently set so the turning is on the left joystick, but you can change the appropiate channels to put them on the same joystick. VexRecieve calls a function which cleans up the input, and I don’t write directly to the motor port so I can do further processing of the value.