Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publish PID integrator state for joint velocity and position controllers #375

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pr2_controllers_msgs/msg/JointControllerState.msg
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ float64 set_point
float64 process_value
float64 process_value_dot
float64 error
float64 i_error
float64 time_step
float64 command
float64 p
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class RTServerGoalHandle
//typedef actionlib::ActionServer<Action>::GoalHandle GoalHandle;
typedef actionlib::ServerGoalHandle<Action> GoalHandle;
typedef boost::shared_ptr<Result> ResultPtr;
typedef boost::shared_ptr<Feedback> FeedbackPtr;

uint8_t state_;

Expand All @@ -81,12 +82,15 @@ class RTServerGoalHandle
public:
GoalHandle gh_;
ResultPtr preallocated_result_; // Preallocated so it can be used in realtime
FeedbackPtr preallocated_feedback_;

RTServerGoalHandle(GoalHandle &gh, const ResultPtr &preallocated_result = ResultPtr((Result*)NULL))
: req_abort_(false), req_succeed_(false), gh_(gh), preallocated_result_(preallocated_result)
RTServerGoalHandle(GoalHandle &gh, const ResultPtr &preallocated_result = ResultPtr((Result*)NULL))
: req_abort_(false), req_succeed_(false), gh_(gh), preallocated_result_(preallocated_result)
{
if (!preallocated_result_)
preallocated_result_.reset(new Result);
if (!preallocated_feedback_)
preallocated_feedback_.reset(new Feedback);
}

void setAborted(ResultConstPtr result = ResultConstPtr((Result*)NULL))
Expand Down
4 changes: 4 additions & 0 deletions robot_mechanism_controllers/src/joint_position_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,15 @@ void JointPositionController::update()
{
if(controller_state_publisher_ && controller_state_publisher_->trylock())
{
double p_error, i_error, d_error;
pid_controller_.getCurrentPIDErrors(&p_error, &i_error, &d_error);

controller_state_publisher_->msg_.header.stamp = time;
controller_state_publisher_->msg_.set_point = command_;
controller_state_publisher_->msg_.process_value = joint_state_->position_;
controller_state_publisher_->msg_.process_value_dot = joint_state_->velocity_;
controller_state_publisher_->msg_.error = error;
controller_state_publisher_->msg_.i_error = i_error;
controller_state_publisher_->msg_.time_step = dt_.toSec();
controller_state_publisher_->msg_.command = commanded_effort;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,36 @@ void JointTrajectoryActionController::update()
}
controller_state_publisher_->unlockAndPublish();
}
if (current_active_goal_follow)
{
current_active_goal_follow->preallocated_feedback_->header.stamp = time;
current_active_goal_follow->preallocated_feedback_->joint_names.resize(joints_.size());
current_active_goal_follow->preallocated_feedback_->desired.positions.resize(joints_.size());
current_active_goal_follow->preallocated_feedback_->desired.velocities.resize(joints_.size());
current_active_goal_follow->preallocated_feedback_->desired.accelerations.resize(joints_.size());
current_active_goal_follow->preallocated_feedback_->actual.positions.resize(joints_.size());
current_active_goal_follow->preallocated_feedback_->actual.velocities.resize(joints_.size());
current_active_goal_follow->preallocated_feedback_->error.positions.resize(joints_.size());
current_active_goal_follow->preallocated_feedback_->error.velocities.resize(joints_.size());
for (size_t j = 0; j < joints_.size(); ++j)
{
current_active_goal_follow->preallocated_feedback_->joint_names[j] = joints_[j]->joint_->name;
current_active_goal_follow->preallocated_feedback_->desired.positions[j] = q[j];
current_active_goal_follow->preallocated_feedback_->desired.velocities[j] = qd[j];
current_active_goal_follow->preallocated_feedback_->desired.accelerations[j] = qdd[j];
current_active_goal_follow->preallocated_feedback_->actual.positions[j] = joints_[j]->position_;
current_active_goal_follow->preallocated_feedback_->actual.velocities[j] = joints_[j]->velocity_;
current_active_goal_follow->preallocated_feedback_->error.positions[j] = error[j];
current_active_goal_follow->preallocated_feedback_->error.velocities[j] = joints_[j]->velocity_ - qd[j];
}
const actionlib_msgs::GoalID goalID = current_active_goal_follow->gh_.getGoalID();
ros::Duration time_from_start = time - goalID.stamp;
current_active_goal_follow->preallocated_feedback_->desired.time_from_start = time_from_start;
current_active_goal_follow->preallocated_feedback_->actual.time_from_start = time_from_start;
current_active_goal_follow->preallocated_feedback_->error.time_from_start = time_from_start;
current_active_goal_follow->gh_.publishFeedback(*current_active_goal_follow->preallocated_feedback_);

}
}

++loop_count_;
Expand Down
4 changes: 4 additions & 0 deletions robot_mechanism_controllers/src/joint_velocity_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,14 @@ void JointVelocityController::update()
{
if(controller_state_publisher_ && controller_state_publisher_->trylock())
{
double p_error, i_error, d_error;
pid_controller_.getCurrentPIDErrors(&p_error, &i_error, &d_error);

controller_state_publisher_->msg_.header.stamp = time;
controller_state_publisher_->msg_.set_point = command_;
controller_state_publisher_->msg_.process_value = joint_state_->velocity_;
controller_state_publisher_->msg_.error = error;
controller_state_publisher_->msg_.i_error = i_error;
controller_state_publisher_->msg_.time_step = dt_.toSec();
controller_state_publisher_->msg_.command = command;

Expand Down