Eric_J
November 21, 2013, 5:52pm
1
I am trying to make a structure that can be used to mirror motors when starting on one side of the field compared to the other in ROBOTC. I am currently trying:
#define mirrormotor[port1] port1
#define mirrormotor[port2] port2
#define mirrormotor[port3] port3
#define mirrormotor[port4] port4
#define mirrormotor[port5] port5
#define mirrormotor[port6] port6
#define mirrormotor[port7] port7
#define mirrormotor[port8] port8
#define mirrormotor[port9] port9
#define mirrormotor[port10] port10
but it does not compile. The idea is that if you have 4 drive motors, you could say port4>port5, port5>port4 etc. to make switching easy. Is there a way I can create an array in the precompile defines store the motor setup?
I am trying to make a structure that can be used to mirror motors when starting on one side of the field compared to the other in ROBOTC. I am currently trying:
#define mirrormotor[port1] port1
#define mirrormotor[port2] port2
#define mirrormotor[port3] port3
#define mirrormotor[port4] port4
#define mirrormotor[port5] port5
#define mirrormotor[port6] port6
#define mirrormotor[port7] port7
#define mirrormotor[port8] port8
#define mirrormotor[port9] port9
#define mirrormotor[port10] port10
but it does not compile. The idea is that if you have 4 drive motors, you could say port4>port5, port5>port4 etc. to make switching easy. Is there a way I can create an array in the precompile defines store the motor setup?
Why can’t you just negate the pwm value before you set it or use the bMotorReflected array?
Eric_J
November 21, 2013, 6:05pm
3
The concept I have is that only in autonomous are certain motors read from other motors (right side drive from left side, and left side drive from right side) to allow the user to mirror an autonomous for the opposite side of the field. If I was just making the values negative this would not work because if you were turning right by running the left side wheels, it would just run the left side backwards instead of running the right side motors to turn left.
The concept I have is that only in autonomous are certain motors read from other motors (right side drive from left side, and left side drive from right side) to allow the user to mirror an autonomous for the opposite side of the field. If I was just making the values negative this would not work because if you were turning right by running the left side wheels, it would just run the left side backwards instead of running the right side motors to turn left.
All of this code is generic (“pseudo”) and not RobotC-specific. I’m just gonna get the idea down here.
Make a function like this:
void runAuton(int side1, int side2)
{
if (!reversed)
{
motor[left] = side1;
motor[right] = side2;
}
else
{
motor[left] = side2;
motor[right] = side1;
}
}
Then declare a boolean at the top called “reversed” and set it to true to flip the sides or false not to. Instead of calling motor set commands, instead use runAuton(…) with the left and right values.
You could also set individual motors like this:
void runSide1(int side1)
{
if (!reversed)
motor[left] = side1;
else
motor[right] = side1;
}
void runSide2(int side2)
{
if (!reversed)
motor[left] = side2;
else
motor[right] = side2;
}
Perhaps something like this would work.
#pragma config(Motor, port1, , tmotorVex393, openLoop)
#pragma config(Motor, port2, , tmotorVex393, openLoop)
#pragma config(Motor, port3, , tmotorVex393, openLoop)
#pragma config(Motor, port4, , tmotorVex393, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
tMotor theMotors kNumbOfRealMotors ];
void
InitMotorsNormal()
{
int index;
// map 1 to 1
for(index=port1;index<kNumbOfRealMotors;index++)
theMotors index ] = index;
}
void
InitMotorsSwitched()
{
// I have no idea of the mapping for your robot
theMotors port4 ] = port1;
theMotors port3 ] = port2;
theMotors port2 ] = port3;
theMotors port1 ] = port4;
}
task main()
{
// test code
InitMotorsNormal();
motor theMotors port1 ] ] = 127;
wait1Msec(1000);
motor theMotors port1 ] ] = 0;
wait1Msec(1000);
// test the other way around
InitMotorsSwitched();
motor theMotors port1 ] ] = 127;
wait1Msec(1000);
motor theMotors port1 ] ] = 0;
while(1)
wait1Msec(10);
}