Steering wheel problems

I’m working on controlling our robot with a steering wheel on port 1, and a throttle on port 2. I have the following definitions at the top of user_routines.c:

#define WHEEL p1_x-127				//Steering wheel on port 1
#define THROTTLE p2_y-127			//Throttle joystick on port 2
#define PIVOT_DISABLE p2_sw_trig	//Trigger button on port 2, disables in-place rotation
#define DEAD 7						//Dead zone where joystick input is ignored
#define LEFT pwm15					//Left drive motor
#define RIGHT pwm16					//Right drive motor

I also have these nifty functions:


int isActive(int x)
{
  if(abs(x)>DEAD)
    return 1;
  else
    return 0;
}

double turnRatio(void)
{
  return 1-abs(WHEEL)/127.1;
}

Then, in the driving routine, I have this code:

LEFT=0;
RIGHT=0;
if(!isActive(THROTTLE))
{
  if(isActive(WHEEL)&&!PIVOT_DISABLE)
  {
    LEFT=WHEEL;
    RIGHT=0-WHEEL-1;
  }
}
else
{
  LEFT=THROTTLE;
  RIGHT=THROTTLE;
  if(WHEEL>DEAD)
  {
    RIGHT*=turnRatio();
  }
  else if(WHEEL<-DEAD)
  {
    LEFT*=turnRatio();
  }
}
if((THROTTLE<-DEAD)&&(WHEEL<-DEAD))
  LEFT-=254*turnRatio();
if((THROTTLE<-DEAD)&&(WHEEL>DEAD))
  RIGHT-=254*turnRatio();
LEFT+=127;
RIGHT+=127;

I have tested this code in RobotEmu2 countless times, and it acts as intended (pivot when wheel is engaged without throttle, go straight with throttle but no wheel, arc with both), but when I actually hook up the equipment to the OI and RC, pwm15 and pwm16 show seemingly random values in Dashboard. I don’t think that it’s a problem with the actual controllers, because the actual values of p1_x and p2_y are as expected. I can’t figure out why there’s a discrepancy in operation between the emulator and the actual RC, and it’s driving me nuts. Anything to help me figure out why this is happening would be appreciated.

Well, since RoboEmu2 just came out not to long ago, there are still some bugs that are not fixed (I’m not sure how long Rob was working on it [testing, debugging, etc…] before releasing it). What does it show when you put the joystick in full forward in both RoboEmu & the Dashboard?

How often are you calling the Generate_Pwms() function?

PWMs 13-16 are special. They get generated directly from the RC’s “user” processor, so they can be updated more quickly than the communication with the “master” processor occurs. If you never call Generate_Pwms(), they don’t update. But if they get updated too quickly, they get squirrely.

I suspect variable overflow.
LEFT and RIGHT are pretty restricted.

I wondered about bugs in RoboEmu2, but I discarded the idea, since the code seems like it should work. When I move the joystick full forward in RoboEmu2, I get 254 on both PWMs, which makes sense. When I move the joystick full forward on the RC, pwm15 goes to 254. If I twist the wheel back and forth, and let it recenter, maybe only pwm16 will go to 254. It’s very sporatic.

I’m pretty sure that I have Generate_Pwms() at the bottom of the 26.2ms routine, but I’ll check for sure on Tuesday. That is where I’m supposed to call it, no?

How do you mean?