jgannon
15-01-2005, 17:16
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.
#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.