View Single Post
  #7   Spotlight this post!  
Unread 23-02-2016, 17:52
Foster Foster is offline
Engineering Program Management
VRC #8081 (STEMRobotics)
Team Role: Mentor
 
Join Date: Jul 2007
Rookie Year: 2005
Location: Delaware
Posts: 1,385
Foster has a reputation beyond reputeFoster has a reputation beyond reputeFoster has a reputation beyond reputeFoster has a reputation beyond reputeFoster has a reputation beyond reputeFoster has a reputation beyond reputeFoster has a reputation beyond reputeFoster has a reputation beyond reputeFoster has a reputation beyond reputeFoster has a reputation beyond reputeFoster has a reputation beyond repute
Re: Thoughts On Comments In Team Code

So I comment my code a lot, but I don't comment the obvious. Like setting the speed to the motors is pretty clear from the code. But I did change the variable names on the code to make it clear it was front_left and not f1. (See you looked to "is that a one or an L"). Same thing with the dashboard. The code is clear, so the "set the dashboard" comments don't add any value. A reminder about the inversion isn't needed since we saw the comment 7 lines before, but it's a little weird, so worth a comment.

And if this is where the drive speed is actually set then I'd do the speed inversion here. That way the entire stack on top is going Foward is positive (+) Reverse is negative (-) and does not need to do the "well the right motors need to be inverted" every place else. That would also get rid of the need to re-invert it back for the display. That would reduce some code complexity.

My 2 cents since you asked, your mileage WILL vary.


Code:
void DriveBase::DriveTank(float left_speed, float right_speed){
	//This method drives each side of the robot using set values
	//The values are not changed in any way
	//Since the right motors are opposite of the left motors, their values are inverted in the command
	//Because of this, when the speeds are output to the SmartDashboard we invert the inverted value

	front_left_motor->Set(left_speed); //Set the motor speeds
	front_right_motor->Set(right_speed);
	back_left_motor->Set(left_speed);
	back_right_motor->Set(right_speed);

	SmartDashboard::PutNumber("Left Speed", left_speed); 
	SmartDashboard::PutNumber("Right Speed", right_speed * -1); //inverted right speed to make the number positive on the display
}
And with the inversion done here

Code:
void DriveBase::DriveTank(float left_speed, float right_speed){
	//This method drives each side of the robot. Forward is positive speeds, reverse is negative speeds.
	//The values are not changed in any way
	//Since the right motors are opposite of the left motors, their values are inverted when we set them

	front_left_motor->Set(left_speed); //Set the motor speeds
	front_right_motor->Set(right_speed * (-1) );
	back_left_motor->Set(left_speed);
	back_right_motor->Set(right_speed * (-1) );

	SmartDashboard::PutNumber("Left Speed", left_speed); 
	SmartDashboard::PutNumber("Right Speed", right_speed); 
}
__________________
Foster - VEX Delaware - 17 teams -- Chief Roboteer STEMRobotics.org
2010 - Mentor of the Year - VEX Clean Sweep World Championship
2006-2016, a decade of doing VEX, time really flies while having fun
Downingtown Area Robotics Web site and VEXMen Team Site come see what we can do for you.

Last edited by Foster : 23-02-2016 at 18:02. Reason: Too much time on my hands