Well, I'm pretty new to the WPILib, but this is what I would do.
Code:
class Fred2 : public SimpleRobot {
public:
Fred2();
~Fred2();
void Autonomous();
void OperatorControl();
private:
OperatorConsole opCon;
/*Drivetrain*/
CANJaguar frontLeftWheelMtr;
CANJaguar rearLeftWheelMtr;
CANJaguar frontRightWheelMtr;
CANJaguar rearRightWheelMtr;
RobotDrive drivetrain;
/*Arm*/
CANJaguar longArmMtr;
CANJaguar shortArmMtr;
CANJaguar wristMtr;
Relay clawRly;
DigitalInput clawClosedSwitch;
DigitalInput clawOpenedSwitch;
/*Deployer*/
Deployer deployer;
/*Flippers*/
Servo flipperReleaseServo;
};
Code:
Fred2::Fred2() :
/*Drivetrain*/
frontLeftWheelMtr(frontLeftWheelMtrDevNum),
rearLeftWheelMtr(rearLeftWheelMtrDevNum),
frontRightWheelMtr(frontRightWheelMtrDevNum),
rearRightWheelMtr(rearRightWheelMtrDevNum),
drivetrain(frontLeftWheelMtr, rearLeftWheelMtr,
frontRightWheelMtr, rearRightWheelMtr),
/*Arm*/
/*Motors*/
longArmMtr(longArmMtrDevNum),
shortArmMtr(shortArmMtrDevNum),
wristMtr(wristMtrDevNum),
clawRly(clawRlyChannel),
/*Sensors*/
clawClosedSwitch(digitalModuleSlot, clawClosedSwitchChannel),
clawOpenedSwitch(digitalModuleSlot, clawOpenedSwitchChannel),
/*Flippers*/
flipperReleaseServo(digitalModuleSlot, flipperReleaseServoChannel)
{ /*Init Code*/
drivetrain.SetInvertedMotor(RobotDrive::kFrontLeftMotor,
driveMotorInvert[0]);
drivetrain.SetInvertedMotor(RobotDrive::kRearLeftMotor,
driveMotorInvert[1]);
drivetrain.SetInvertedMotor(RobotDrive::kFrontRightMotor,
driveMotorInvert[2]);
drivetrain.SetInvertedMotor(RobotDrive::kRearRightMotor,
driveMotorInvert[3]);
}
I didn't have to rewrite any functions to avoid using new, so I don't really know what you're getting at. I'm just wondering if it's that people don't teach this method (why?) or if there's actually a good reason for it.