Skip to content

Commit

Permalink
[effort_controllers] JointGroupPositionController: Set to current pos…
Browse files Browse the repository at this point in the history
…ition in starting

Currently, the target position upon starting is all zeros. This is not
great if a command is not issued immediately. To be safer, set the goal
position to the current sensed position and also reset the PID internal
state upon starting.
  • Loading branch information
wxmerkt committed Sep 4, 2020
1 parent 6653d90 commit e25a037
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class JointGroupPositionController : public controller_interface::Controller<har

bool init(hardware_interface::EffortJointInterface* hw, ros::NodeHandle &n);
void update(const ros::Time& /*time*/, const ros::Duration& /*period*/);
void starting(const ros::Time& /*time*/);

std::vector< std::string > joint_names_;
std::vector< hardware_interface::JointHandle > joints_;
Expand Down
14 changes: 13 additions & 1 deletion effort_controllers/src/joint_group_position_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,26 @@ namespace effort_controllers
return true;
}

void JointGroupPositionController::starting(const ros::Time& time)
{
std::vector<double> current_positions(n_joints_, 0.0);
for (std::size_t i = 0; i < n_joints_; ++i)
{
current_positions[i] = joints_[i].getPosition();
enforceJointLimits(current_positions[i], i);
pid_controllers_[i].reset();
}
commands_buffer_.writeFromNonRT(current_positions);
}

void JointGroupPositionController::update(const ros::Time& time, const ros::Duration& period)
{
std::vector<double> & commands = *commands_buffer_.readFromRT();
for(unsigned int i=0; i<n_joints_; i++)
{
double command_position = commands[i];

double error; //, vel_error;
double error;
double commanded_effort;

double current_position = joints_[i].getPosition();
Expand Down

0 comments on commit e25a037

Please sign in to comment.