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

[Servo] Improve support for switching planning group #2333

Closed
wants to merge 14 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
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ int main(int argc, char* argv[])
RCLCPP_INFO_STREAM(LOGGER, servo.getStatusMessage());
while (rclcpp::ok())
{
servo.updateParams(); // This can be skipped if your application will not be updating parameters.
const KinematicState joint_state = servo.getNextJointState(joint_jog);
const StatusCode status = servo.getStatus();

Expand Down
1 change: 1 addition & 0 deletions moveit_ros/moveit_servo/demos/cpp_interface/demo_pose.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ int main(int argc, char* argv[])
rclcpp::WallRate tracking_rate(1 / servo_params.publish_period);
while (!stop_tracking && rclcpp::ok())
{
servo.updateParams(); // This can be skipped if your application will not be updating parameters.
{
std::lock_guard<std::mutex> pguard(pose_guard);
joint_state = servo.getNextJointState(target_pose);
Expand Down
1 change: 1 addition & 0 deletions moveit_ros/moveit_servo/demos/cpp_interface/demo_twist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ int main(int argc, char* argv[])
RCLCPP_INFO_STREAM(LOGGER, servo.getStatusMessage());
while (rclcpp::ok())
{
servo.updateParams(); // This can be skipped if your application will not be updating parameters.
const KinematicState joint_state = servo.getNextJointState(target_twist);
const StatusCode status = servo.getStatus();

Expand Down
34 changes: 23 additions & 11 deletions moveit_ros/moveit_servo/include/moveit_servo/servo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ class Servo
*/
StatusCode getStatus() const;

/**
* \brief Set the current status of servo to the provided status.
* @param status The new status of servo.
*/
void setStatus(const StatusCode status);

/**
* \brief Get the message associated with the current servo status.
* @return The status message.
Expand All @@ -122,14 +128,19 @@ class Servo
* \brief Get the current state of the robot as given by planning scene monitor.
* @return The current state of the robot.
*/
KinematicState getCurrentRobotState() const;
KinematicState getCurrentRobotState();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this not const if it just gets the robot state variable?

This is impacting the constness of a bunch of other functions as well


/**
* \brief Smoothly halt at a commanded state when command goes stale.
* @param The last commanded joint states.
* @return The next state stepping towards the required halting state.
*/
std::pair<bool, KinematicState> smoothHalt(const KinematicState& halt_state) const;
std::pair<bool, KinematicState> smoothHalt(const KinematicState& halt_state);

/**
* \brief Updates the servo parameters and performs validations.
*/
bool updateParams();

private:
/**
Expand All @@ -139,7 +150,7 @@ class Servo
* @param command_frame The command frame name.
* @return The transformation between planning frame and command frame.
*/
Eigen::Isometry3d getPlanningToCommandFrameTransform(const std::string& command_frame) const;
Eigen::Isometry3d getPlanningToCommandFrameTransform(const std::string& command_frame);

/**
* \brief Convert a given twist command to planning frame,
Expand All @@ -150,21 +161,21 @@ class Servo
* @param command The twist command to be converted.
* @return The transformed twist command.
*/
TwistCommand toPlanningFrame(const TwistCommand& command) const;
TwistCommand toPlanningFrame(const TwistCommand& command);

/**
* \brief Convert a given pose command to planning frame
* @param command The pose command to be converted
* @return The transformed pose command
*/
PoseCommand toPlanningFrame(const PoseCommand& command) const;
PoseCommand toPlanningFrame(const PoseCommand& command);

/**
* \brief Compute the change in joint position required to follow the received command.
* @param command The incoming servo command.
* @return The joint position change required (delta).
*/
Eigen::VectorXd jointDeltaFromCommand(const ServoInput& command, const moveit::core::RobotStatePtr& robot_state);
Eigen::VectorXd jointDeltaFromCommand(const ServoInput& command);

/**
* \brief Updates data depending on joint model group
Expand All @@ -178,11 +189,6 @@ class Servo
*/
bool validateParams(const servo::Params& servo_params) const;

/**
* \brief Updates the servo parameters and performs validations.
*/
bool updateParams();

/**
* \brief Create and initialize the smoothing plugin to be used by servo.
*/
Expand Down Expand Up @@ -214,6 +220,12 @@ class Servo
std::unique_ptr<CollisionMonitor> collision_monitor_;

pluginlib::UniquePtr<online_signal_smoothing::SmoothingBaseClass> smoother_ = nullptr;

moveit::core::RobotStatePtr robot_state_;
const moveit::core::JointModelGroup* joint_model_group_;
std::vector<std::string> joint_names_;

bool invalid_parameter_update_;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need this if it's used as synonymous with servo being paused.

I also can't find that line in the PR review, but I think your changes make you able to remove the servo_paused_ member variable as well?

};

} // namespace moveit_servo
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ enum class StatusCode : int8_t
DECELERATE_FOR_LEAVING_SINGULARITY = 3,
DECELERATE_FOR_COLLISION = 4,
HALT_FOR_COLLISION = 5,
JOINT_BOUND = 6
JOINT_BOUND = 6,
PAUSED = 7
};

const std::unordered_map<StatusCode, std::string> SERVO_STATUS_CODE_MAP(
Expand All @@ -68,7 +69,8 @@ const std::unordered_map<StatusCode, std::string> SERVO_STATUS_CODE_MAP(
{ StatusCode::DECELERATE_FOR_LEAVING_SINGULARITY, "Moving away from a singularity, decelerating" },
{ StatusCode::DECELERATE_FOR_COLLISION, "Close to a collision, decelerating" },
{ StatusCode::HALT_FOR_COLLISION, "Collision detected, emergency stop" },
{ StatusCode::JOINT_BOUND, "Close to a joint bound (position or velocity), halting" } });
{ StatusCode::JOINT_BOUND, "Close to a joint bound (position or velocity), halting" },
{ StatusCode::PAUSED, "Servo paused" } });

// The datatype that specifies the type of command that servo should expect.
enum class CommandType : int8_t
Expand Down
Loading
Loading