|
Re: potentiometer programming help
This is the code i made
#include "Main.h"
void OperatorControl ( void )
{
int joy_y_port1;
int joy_x_port2;
unsigned char left_output;
unsigned char right_output;
int limit = 1;
int limit2 = 1;
unsigned int steering;
int pressure;
while ( 1 )
{
PrintToScreen ( "steering value before getting steering reading=%d\n" , (long)¬
steering ) ;
joy_y_port1 = GetOIAInput ( 1 , 2 ) ; // get joystick data
left_output = (( joy_y_port1 -127 ) +127) ; // drive motor
SetRelay ( 8 , 1 , -1 ) ; // send power to the compressor
pressure = GetDigitalInput ( 9 ) ; // get air pressure reading
while ( pressure >= 120 )
{
SetRelay ( 8 , 0 , -1 ) ;
break ; // return to driving
}
steering = GetAnalogInput ( 1 ) ; // read pot
joy_x_port2 = GetOIAInput ( 2 , 2 ) ; // get joystick data
if ( joy_x_port2 > 245 || joy_x_port2 < 10 ) // if pushed hard left or right
{
right_output = (( joy_x_port2 - 127 )/2 +127) ; // use joystick over r¬
ide
}
if ( steering >663 ) // correcting towards the left
{
SetPWM ( 3 , 139 ) ;
PrintToScreen ( "this steering value should be above 512=%d\n" , (long)¬
steering ) ;
}
if ( steering <= 308 ) // correcting towards the right
{
SetPWM ( 3 , 115 ) ;
PrintToScreen ( "this steering value should be below 512 =%d\n" , (long¬
)steering ) ;
}
SetPWM ( 1 , left_output ) ;
SetPWM ( 2 , left_output ) ;
SetPWM ( 3 , right_output ) ;
OIToRelay ( 1 , 1 , 2 , 1 ) ;
}
}
I get readings from the device but it doesn't work the way i want it to. The purpose it to keep a solo wheel pointed directly outward and when the wheel is turned to the right with the joystick i want the pot sensor to recenter the wheel when we let go of the joystick and vice versa for the right.
|