View Single Post
  #8   Spotlight this post!  
Unread 23-02-2016, 19:30
King Nerd III's Avatar
King Nerd III King Nerd III is offline
Chief Programmer/Head of Autonomous
AKA: Isaac
FRC #1410 (The Kraken)
Team Role: Programmer
 
Join Date: Jan 2014
Rookie Year: 2014
Location: Denver, CO
Posts: 113
King Nerd III is an unknown quantity at this point
Re: Thoughts On Comments In Team Code

Quote:
Originally Posted by Foster View Post
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); 
}
In my experience, it doesn't really change much if you have it in the method or the command, as either way it's just one or two * -1 somewhere in the code. The reason we do it this way is because it just makes things easier when calling it in different commands, but to each their own!
__________________
Isaac
Chief of Programming and Head of Autonomous Control
FRC Team 1410