Skip to content

Commit

Permalink
Fix warning: taking the absolute value of unsigned type 'unsigned sho…
Browse files Browse the repository at this point in the history
…rt' has no effect [-Wabsolute-value]
  • Loading branch information
fspindle committed Nov 17, 2023
1 parent 893f6b7 commit 714800e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions modules/robot/include/visp3/robot/vpPololu.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,16 +276,16 @@ class VISP_EXPORT vpPololu
*
* \param speed_rad_s : Speed converted to rad/s.
*
* \return speed : Speed in units of (0.25 μs)/(10 ms).
* \return Signed speed in units of (0.25 μs)/(10 ms).
*
* \sa speedToRadS()
*/
unsigned short radSToSpeed(float speed_rad_s) const;
short radSToSpeed(float speed_rad_s) const;

/*!
* Convert Pololu's pwm velocity to rad/s velocity.
*
* \param[in] speed : Speed in units of (0.25 μs)/(10 ms).
* \param[in] speed : Signed speed in units of (0.25 μs)/(10 ms).
*
* \return Speed converted to rad/s.
*
Expand Down
10 changes: 5 additions & 5 deletions modules/robot/src/real-robot/pololu-maestro/vpPololu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ bool vpPololu::connected() const
return true;
}

unsigned short vpPololu::radSToSpeed(float speed_rad_s) const
short vpPololu::radSToSpeed(float speed_rad_s) const
{
return static_cast<unsigned short>((speed_rad_s / 100.f) * (m_range_pwm / m_range_angle));
return static_cast<short>((speed_rad_s / 100.f) * (m_range_pwm / m_range_angle));
}

unsigned short vpPololu::getPwmPosition() const
Expand Down Expand Up @@ -194,7 +194,7 @@ void vpPololu::setAngularPosition(float pos_rad, float vel_rad_s)
{
if ((m_min_angle <= pos_rad) && (pos_rad <= m_max_angle)) {
unsigned short pos_pwm = radToPwm(pos_rad);
unsigned short pos_speed = radSToSpeed(vel_rad_s);
unsigned short pos_speed = std::fabs(radSToSpeed(vel_rad_s));
// Handle the case where pos_speed = 0 which corresponds to the pwm max speed
if (pos_speed == 0) {
pos_speed = 1;
Expand Down Expand Up @@ -237,7 +237,7 @@ void vpPololu::setPwmPosition(unsigned short pos_pwm, unsigned short speed_pwm)

void vpPololu::setAngularVelocity(float vel_rad_s)
{
short pwm_vel = static_cast<short>(std::abs(radSToSpeed(vel_rad_s)));
short pwm_vel = radSToSpeed(vel_rad_s);

// Handle the case where vel_rad_s != 0 but pwm_vel == 0. In that case we set a minimal speed
if (pwm_vel == 0) {
Expand All @@ -256,7 +256,7 @@ void vpPololu::setPwmVelocity(short pwm_vel)
unsigned short vel_speed;
unsigned short vel_target_position;
if (pwm_vel <= 1000) {
vel_speed = static_cast<short>(std::abs(pwm_vel));
vel_speed = static_cast<unsigned short>(std::abs(pwm_vel));
if (pwm_vel > 0) {
vel_target_position = m_max_pwm;
}
Expand Down

0 comments on commit 714800e

Please sign in to comment.