Hey I am making a program for a robot with swerving drive, what I have read is that I need to map the Ch 1&2 (X&Y axis) to an (X, Y) plane were X is the power and Y is theta or the angle that the wheels need to be set to, I can set the wheels to an angle. But I lack the knowledge on how to set the angle based on the joystick. If it is any help I am using VexEDR Cortex, and the standard controller that comes along with it.
Choose a maximum and minimum angle you want to go to, and then determine a simple equations on the form motorPos = rate * joystickPos. If you want it to turn at a non-constant rate, you can develop a piece-wise function, using linear slopes in different joystick ranges, or you can develop a third order equation with the profile you want. This can be done mathematically (difficult) or experimentally (took about 3 minutes). I drew the shape i wanted, took a TI 84 calculator and set the graph window to the range i wanted, then just tweaked A values in y=A * x^3 until i got the shape i wanted.
First of all thanks for responding, however I need further clarification. This is the code I have written, I know I haven’t written if & while commands for two other rotating motors,
From
The code I wrote before I could get it to rotate to one encoder value, but not a variable setting.
When downloaded to the robot nothing works
int motorPos;
task main(){
resetMotorEncoder(FRR);//"FRR" stands for front right rotate
resetMotorEncoder(BRR);//"BRR" = back right rotate
resetMotorEncoder(FLR);
resetMotorEncoder(BLR);//<-- to clear encoders, so they are set to 0 facing forward, for every 180 encoder counts rotates 90 degrees
resetMotorEncoder(BLD);
resetMotorEncoder(FRD);//"FRD" stands for front right drive
resetMotorEncoder(BRD);//"BRD" = back right drive ect..
resetMotorEncoder(FLD);
while (1==1){
motorPos = 1/10*(vexRT[Ch1]*vexRT[Ch1]*vexRT[Ch1]);} // Three vexRT[Ch1] for X^3
//If statements for setting the angles of the wheels, works to a c
if(SensorValue[I2C_7] < motorPos){
while (SensorValue[I2C_7] < motorPos){
motor(FRR) =30;}
motor(FRR) = 0;}
if(SensorValue[I2C_7] > motorPos){
while (SensorValue[I2C_7] > motorPos){
motor(FRR) =-30;}
motor(FRR) = 0;}
if(SensorValue[I2C_8] < motorPos){
while (SensorValue[I2C_8] < motorPos){
motor(FRR) =-30;}
motor(FRR) = 0;}
if(SensorValue[I2C_8] > motorPos){
while (SensorValue[I2C_8] > motorPos){
motor(FRR) =30;}
motor(FRR) = 0;}}
I know you said set a range of angles I need, so would the range be -320=<X=<320? So it could rotate -180 - 180?
Instead of while statements and if statements, i might try something like proportional control, setting the motors equal to a scaling factor (P value in PID) of the difference between your command position (motorPos) and you actual position (sensor value).
I would worry that you are never eliminating all error, so you are never exiting the while loops inside the if statements. Alternatively, if you want to keep that structure, add a tolerance band in your conditions so that if it gets close, it will move on.
Last thing, be careful with your assignment to motorPos, depending on what data type it is, it may overflow and have unintended values. Just monitor the motorPos variable’s values and make sure it is reporting what you expect it too.
For your range, you have an input range of -127 to positive 126, and an equation of (0.1) x^3, so your angle range is effectively -204838.3 to 200037.6 sensor values. I dunno what the sensor value to degrees conversion rate is, but it seems like that may be high, so your equation may need work too.
Thanks very much Robo, I have been working on the code, for awhile now, I got the PIDs finally working, how ever, the Joysticks I am using doesn’t quite return to 0,0 so i am trying to implement a dead zone into my code so it doesn’t twitch in circles,
int Channel1;
int threshold;
void deadZoneCheck()
{
threshold = 15;
if(abs(vexRT[Ch1]) > threshold)
Channel1 = vexRT[Ch1];
else
Channel1 = 0;
the above code states the dead zone zone,
and then the code below should run the dead zone check but it spits out
this error
while(true)
{
while (deadZoneCheck())
{
pidRequestedValue = pidRequestedValue + (Channel1/4);
pidRequestedValue2 = pidRequestedValue2 + (Channel1/4);
pidRequestedValue3 = pidRequestedValue3 + (Channel1/4);
pidRequestedValue4 = pidRequestedValue4 + (Channel1/4);
}
}
Never mind I found what was wrong…
int Channel1;
int threshold;
task deadZoneCheck()
{
while(true)
{
threshold = 15;
if(abs(vexRT[Ch1]) > threshold)
Channel1 = vexRT[Ch1];
else
Channel1 = 0;
}
}
if i set the it to a task and repeat the code
i can call for
later instead or vexRT[Ch1]
pidRequestedValue = pidRequestedValue + (Channel1/4);