Hood raised zero#10
Conversation
|
Unfortunately github doesn't let me comment lines that didn't change so I'm putting it here as a reminder: Add |
| if(m_hood.GetSupplyCurrent() >= ShooterConstants::zeroingcurrent){ | ||
| m_hood.Set(ControlMode::PercentOutput, 0.0); | ||
| return; | ||
| } | ||
| else if(m_hood.GetSelectedSensorPosition() > ShooterConstants::hoodMax && | ||
| m_angle >= ShooterConstants::hoodMax){ | ||
| m_hood.Set(ControlMode::PercentOutput, 0.0); | ||
| return; | ||
| } | ||
| else if(m_hood.GetSelectedSensorPosition() < ShooterConstants::hoodMin && | ||
| m_angle <= ShooterConstants::hoodMin){ | ||
| m_hood.Set(ControlMode::PercentOutput, 0.0); | ||
| return; | ||
| } | ||
| else { | ||
| m_hood.Set(ControlMode::Position, m_angle); | ||
| } |
There was a problem hiding this comment.
I'd suggest refactoring this into:
| if(m_hood.GetSupplyCurrent() >= ShooterConstants::zeroingcurrent){ | |
| m_hood.Set(ControlMode::PercentOutput, 0.0); | |
| return; | |
| } | |
| else if(m_hood.GetSelectedSensorPosition() > ShooterConstants::hoodMax && | |
| m_angle >= ShooterConstants::hoodMax){ | |
| m_hood.Set(ControlMode::PercentOutput, 0.0); | |
| return; | |
| } | |
| else if(m_hood.GetSelectedSensorPosition() < ShooterConstants::hoodMin && | |
| m_angle <= ShooterConstants::hoodMin){ | |
| m_hood.Set(ControlMode::PercentOutput, 0.0); | |
| return; | |
| } | |
| else { | |
| m_hood.Set(ControlMode::Position, m_angle); | |
| } | |
| const double curr_hood_angle = m_hood.GetSelectedSensorPosition(); | |
| const bool hood_overcurrent = m_hood.GetSupplyCurrent() >= ShooterConstants::zeroingcurrent; | |
| const bool hood_too_high = curr_hood_angle > ShooterConstants::hoodMax && | |
| m_angle >= ShooterConstants::hoodMax; | |
| const bool hood_too_low = curr_hood_angle < ShooterConstants::hoodMin && | |
| m_angle <= ShooterConstants::hoodMin; | |
| if (hood_overcurrent || hood_too_high || hood_too_low) { | |
| m_hood.Set(ControlMode::PercentOutput, 0.0); | |
| } else { | |
| m_hood.Set(ControlMode::Position, m_angle); | |
| } |
- make one call to
GetSelectedSensorPosition()and cache the value in a local variable so you're not repeatedly hammering the CAN bus for the same data. - remove the return statements in each branch since the cases are already mutually-exclusive. leaving them in might cause bugs later on if stuff is added after this code block (such as the smartdashboard call).
|
I'd personally avoid mixing and matching between I think it's easier to debug hood issues if the motor is always commanded as |
No description provided.