Hand written Arcade drive

{hand hacked quote attribution from RobotC official answers thread}

What have you tried already?

The Houston Vex 100point+ driver skills robot was rumored to have an advanced hand coded drive function. Many teams have alluded to having similar, and believe it is an important component.
Does anyone want to post their code, or at least outlines of it?

Walkthrough/outline of the BEST 2009 Arcade code below:

  • parabolicScale shows that you don’t need to use the joystick value directly
    • adds deadband (16)
    • adds parabolic function, something like offset*offset/(offsetmax)
    • adds scale to make sure that the RC joystick value max can be reached (probably not needed with Vexnet Joystick calibration)
  • maxvalue limits: Could be written more compactly as a nested trinary, but it just makes sure that the assigned motor values don’t go out of range.

Note that Arcade code is just like holonomic code without the extra rotation component, so check the holonomic code threads for more ideas.

This example code is from BEST 2009, using the “Brain” MSP430 dual cpu,
but it is plain C code, and should be a good example template for RobotC

   //Drive Code,  Rcrange is 0..255 with RC_IDLE_VAL=127 means stop
    yInput=parabolicScale(getRcValue(1,16,100),125)-RCIDLEVAL; //speed
    xInput=parabolicScale(getRcValue(0,16,100),125)-RCIDLEVAL; //steer
    leftValue  = yInput + xInput;  // combine the inputs
    rightValue = yInput - xInput;  //  to create output deltas
// bound the delta values (remember RCIDLEVAL is half RCMAXVAL)  
    if (leftValue  >  RCIDLEVAL) leftValue  =  RCIDLEVAL;  // will end up being RCMAXVAL
    if (leftValue  < -RCIDLEVAL) leftValue  = -RCIDLEVAL;  // will end up being zero
    if (rightValue >  RCIDLEVAL) rightValue =  RCIDLEVAL; 
    if (rightValue < -RCIDLEVAL) rightValue = -RCIDLEVAL; 
    // protobot: m2 = lift, m1=leftw, m0 = rightw
    // output the values and include the idle offset 
    setMotor(0,rightValue+RCIDLEVAL); // right wheel  
    setMotor(1,leftValue+RCIDLEVAL);  // left  wheel 

I don’t remember where I put the code but last year I wrote a pretty nice holonomic drive. It had PID contol even in diver control mode (it didn’t cause problems, because the user could override it easily), and lots of preset functions, like turning exactly 90 degrees at the push of a button. Another great function, because it was holonomic, was the ability to flip the driving contols backwards. If the robot happened to turn around, the driver would flip the contols instead of trying to drive backwards.