Quote:
Originally Posted by bob.wolff68
I agree with lopsided. I'll add a few things as well.
* As a bug/nit - I dont see encoderDist being 'set' or assigned or incremented anywhere. Maybe outside the scope of what you pasted in. But without...it'll not operate as you intend.
* You talk about putting code into the .h header file. Header files are not the best place to put implementations (code). This is because there are other files which may EACH #include such a header file. When it gets included by multiple files, the implementation will be done multiple times and you'll at least get strange errors from the compiler which may be very non-obvious how to fix. Put implementation/code in .cpp files only.
bob
|
In my actual program, Robot.cpp, I currently have this line:
Code:
motorAutomationEncoder(e_encoder_dist, 200, -100, fan_motor_SRX, 1.0);
In other words, I have a variable in Robot.cpp, e_encoder_dist, that reads the distance returned by the encoder. Currently both the header file and the program itself give me the error "use of deleted function CANTalon::CANTalon(const CANTalon&)", and after I changed my function code to this:
Code:
int motorAutomationEncoder(double encoderDist,
double encoderDistThresholdMax,
double encoderDistThresholdMin,
CANTalon motor,
double motorSpeed)
{
if(encoderDist > encoderDistThresholdMax) {
motor.Set(0.0);
}
else if(encoderDist <= encoderDistThresholdMax && encoderDist >= encoderDistThresholdMin) {
motor.Set(motorSpeed);
}
else if(encoderDist < encoderDistThresholdMin) {
motor.Set(0.0);
}
}
...the constantly-shutting-off-and-on problem seems to have disappeared.