Our coding guidelines at work say this about comments:
Quote:
Consider using code comments to document code whose operation is not self-evident to the professional developer (e.g. code reviewer). For example, consider commenting: - Pre-conditions not evident in code, e.g. thread-safety assumptions
- Complex algorithms
- Complex flow of control, e.g. chained asynchronous calls
- Dependencies on global state
- Security considerations
Avoid using comments that repeat self-commenting information found in many code structures. For example, do not add vacuous comments such as "Constructors", "Properties", "Using Statements". Avoid commenting: - Type declarations (e.g. method signatures)
- Method overloads
- Well-understood patterns (e.g. enumerators)
- Clean code
|
You would get these code review comments on your method:
- Document purpose of method and parameters
- Rename fl_motor to front_left_motor, etc.
- Input to the method should be in the orientation of the driver, and translated to motor inputs here. This means you'd negate the right value where it's used to set motor speeds
- Use "- right_speed" rather than "right_speed - 1"
- "Left Speed" should be "Left Drive Speed", etc.
After those changes, the method would look like this:
Code:
/**
* Operate the drive base using tank-style control, where a joystick is
* assigned to each side of the robot and independently controls its speed.
* @param left_speed Desired speed of left side of robot
* @param right_speed Desired speed of right side of robot.
**/
void DriveBase::DriveTank(float left_speed, float right_speed){
front_left_motor->Set(left_speed);
back_left_motor->Set(left_speed);
// Right motors operate in opposite direction of left, so we negate
// the values here to maintain the correct orientation.
front_right_motor->Set(-right_speed);
back_right_motor->Set(-right_speed);
SmartDashboard::PutNumber("Left Drive Speed", left_speed);
SmartDashboard::PutNumber("Right Drive Speed", -right_speed);
}