Skip to content

Commit

Permalink
Fixing #4
Browse files Browse the repository at this point in the history
  • Loading branch information
rbonghi committed Apr 8, 2020
1 parent 5cf02e7 commit 6c59d5d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
2 changes: 2 additions & 0 deletions include/roboteq/motor.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ class Motor : public diagnostic_updater::DiagnosticTask
double velocity, max_velocity;
double effort, max_effort;
double command;
// Motor reduction
double _reduction;

int _control_mode;
motor_status_t _status;
Expand Down
24 changes: 9 additions & 15 deletions src/roboteq/motor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ Motor::Motor(const ros::NodeHandle& nh, serial_controller *serial, string name,
effort = 0;
// Initialize control mode
_control_mode = -1;
// Initialize reduction and get ratio
_reduction = 0;
mNh.getParam(mMotorName + "/ratio", _reduction);
// ROS_INFO_STREAM("to_encoder_ticks:" << _reduction);
// apply the reduction convertion
if(_sensor != NULL)
_reduction = _sensor->getConversion(_reduction);

// Initialize Dynamic reconfigurator for generic parameters
parameter = new MotorParamConfigurator(nh, serial, mMotorName, number);
Expand Down Expand Up @@ -109,15 +116,8 @@ void Motor::initializeMotor(bool load_from_board)
*/
double Motor::to_encoder_ticks(double x)
{
double reduction = 0;
// Get ratio
mNh.getParam(mMotorName + "/ratio", reduction);
//ROS_INFO_STREAM("to_encoder_ticks:" << reduction);
// apply the reduction convertion
if(_sensor != NULL)
reduction = _sensor->getConversion(reduction);
// Return the value converted
return x * (reduction) / (2 * M_PI);
return x * (_reduction) / (2 * M_PI);
}

/**
Expand All @@ -128,14 +128,8 @@ double Motor::to_encoder_ticks(double x)
*/
double Motor::from_encoder_ticks(double x)
{
double reduction = 0;
// Get ratio
mNh.getParam(mMotorName + "/ratio", reduction);
// apply the reduction convertion
if(_sensor != NULL)
reduction = _sensor->getConversion(reduction);
// Return the value converted
return x * (2 * M_PI) / (reduction);
return x * (2 * M_PI) / (_reduction);
}

void Motor::setupLimits(urdf::Model model)
Expand Down

0 comments on commit 6c59d5d

Please sign in to comment.