View Single Post
  #1   Spotlight this post!  
Unread 04-02-2015, 18:46
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
Child function problems

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!
Reply With Quote