ROBOTC v4.55
Background
I have a file called
setDrive.c
. It contains three functions,
setDrive(speed)
,
setDriveLeft(speed)
,
setDriveRight(speed)
. As you can probably imagine, these functions set the respective drive side to
speed
. The functions rely on a
#define DRIVE_MOTORS 4
, where four is the total number of drive motors (two on each side). In the file there are three different variations of the function, one for 2 drive motors, another for 4 drive motors, and yet another for 6. The functions also require specifically named drive motors, i.e. for four motors the drives must be named like
driveRightBack
or
driveLeftFront
. While this is totally usable, it feels clunky to me.
ROBOTC (with VEX2) stores what drive side (if any) a motor is, as a variable of type
TMotorDriveSide
. I would like to use this information in my functions.
My current code
struct _setDriveData {
bool initialized;
TMotorList leftMotors, rightMotors;
int leftMotorsNumb, rightMotorsNumb;
};
static _setDriveData setDriveData;
void setDriveInit() {
getMotorsWithDriveSideType(driveLeft, setDriveData.leftMotors );
getMotorsWithDriveSideType(driveRight, setDriveData.rightMotors);
setDriveData.leftMotorsNumb = sizeof(setDriveData.leftMotors ) / sizeof(setDriveData.leftMotors [0]);
setDriveData.rightMotorsNumb = sizeof(setDriveData.rightMotors) / sizeof(setDriveData.rightMotors[0]);
}
void setDriveLeft(int speed) {
if (!setDriveData.initialized)
setDriveInit();
for (int i=0; i<setDriveData.leftMotorsNumb; i++){
SetMotor(setDriveData.leftMotors*, speed);
}
}
The problem
The lines which are not doing what they are supposed to are the
sizeof
ones.
sizeof(setDriveData.leftMotors)
returns
4
, no matter the length of
setDriveData.leftMotors
. This Stack Overflow answer makes me think that it is returning
4
because it is a pointer.
RobotCIntrinsics.c
, line 1844
getMotorsWithDriveSideType(TMotorDriveSide nType, TMotorList &nMotorList)
The
&nMotorList
means that it’s being passed as a pointer, right?
Thanks,
DMM
My code is attached (as a zip because Vex Forums doesn’t allow
.c
or
.txt
files).*
my code.zip (7.46 KB)