My goal right now is to put everything in our main code (west coast, motor automation, etc.) into child functions in the IterativeRobot.h header file. However, the CANTalon and Talon instances, when initialized within the function itself, executes over and over again as the main TeleopPeriodic section in the main program loops and therefore starts and shuts off the motor over and over again. Here's the code:
Code:
int motorAutomationEncoder(double encoderDist,
double encoderDistThresholdMax,
double encoderDistThresholdMin,
const int motorPort,
double motorSpeed)
{
CANTalon motor(motorPort);
if(encoderDist > encoderDistThresholdMax) {
motor.Set(0.0);
}
else if(encoderDist <= encoderDistThresholdMax && encoderDist >= encoderDistThresholdMin) {
motor.Set(motorSpeed);
}
else if(encoderDist < encoderDistThresholdMin) {
motor.Set(0.0);
}
SmartDashboard::PutNumber('current motor value', motor.Get());
}
I'd appreciate any help. Thanks!