View Single Post
  #5   Spotlight this post!  
Unread 04-02-2015, 19:59
DrOmni9885's Avatar
DrOmni9885 DrOmni9885 is offline
Registered User
FRC #1595 (Dragons)
Team Role: Programmer
 
Join Date: Feb 2013
Rookie Year: 2012
Location: Spokane, WA
Posts: 8
DrOmni9885 is an unknown quantity at this point
Re: Child function problems

Quote:
Originally Posted by bob.wolff68 View Post
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.
Reply With Quote