28 #ifndef QB_MOVE_INTERACTIVE_INTERFACE_H 29 #define QB_MOVE_INTERACTIVE_INTERFACE_H 34 #include <trajectory_msgs/JointTrajectory.h> 75 cylinder_.header.frame_id = device_name +
"_shaft_link";
76 cylinder_.name = device_name +
"_position_reference_cylinder";
77 cylinder_.description =
"motor position reference cylinder.";
82 controls_.header.frame_id = device_name +
"_shaft_link";
83 controls_.name = device_name +
"_position_reference_controls";
84 controls_.description =
"motor position reference controls.";
98 joint_command_pub_ = root_nh.
advertise<trajectory_msgs::JointTrajectory>(
"control/" + device_name +
"_position_and_preset_trajectory_controller/command", 1);
128 void buildCylinder(visualization_msgs::InteractiveMarker &interactive_marker) {
129 visualization_msgs::Marker marker;
130 marker.type = visualization_msgs::Marker::CYLINDER;
131 marker.pose.position.y = 0.02;
132 marker.pose.orientation.w = 1;
133 marker.pose.orientation.x = 1;
134 marker.pose.orientation.y = 0;
135 marker.pose.orientation.z = 0;
136 marker.scale.x = interactive_marker.scale * 0.4;
137 marker.scale.y = interactive_marker.scale * 0.4;
138 marker.scale.z = interactive_marker.scale * 0.4;
139 marker.color.r = 0.35;
140 marker.color.g = 0.35;
141 marker.color.b = 0.35;
142 marker.color.a = 0.75;
144 visualization_msgs::InteractiveMarkerControl control;
145 control.always_visible =
static_cast<unsigned char>(
true);
146 control.markers.push_back(marker);
147 control.orientation_mode = visualization_msgs::InteractiveMarkerControl::FIXED;
148 interactive_marker.controls.push_back(control);
159 visualization_msgs::InteractiveMarkerControl control;
160 control.orientation.w = 1;
161 control.orientation.x = 0;
162 control.orientation.y = 0;
163 control.orientation.z = 1;
164 control.name =
"position";
165 control.interaction_mode = visualization_msgs::InteractiveMarkerControl::ROTATE_AXIS;
166 control.orientation_mode = visualization_msgs::InteractiveMarkerControl::FIXED;
167 interactive_marker.controls.push_back(control);
168 control.name =
"stiffness";
169 control.interaction_mode = visualization_msgs::InteractiveMarkerControl::MOVE_AXIS;
170 control.orientation_mode = visualization_msgs::InteractiveMarkerControl::FIXED;
171 interactive_marker.controls.push_back(control);
184 double to_roll = 0.0;
186 double not_used_1, not_used_2;
199 return to_pose.y - from_pose.y;
208 trajectory_msgs::JointTrajectory
computeJointTrajectories(
const double &displacement_position,
const double &displacement_stiffness) {
209 trajectory_msgs::JointTrajectoryPoint point;
211 point.velocities.resize(2);
212 point.accelerations.resize(2);
215 trajectory_msgs::JointTrajectory trajectory;
217 trajectory.header.frame_id = device_name_ +
"_interactive";
218 trajectory.joint_names.push_back(joint_names_.at(0));
219 trajectory.joint_names.push_back(joint_names_.at(1));
220 trajectory.points.push_back(point);
229 return cylinder_.controls.at(0).markers.at(0).scale.x/0.05 - 0.2;
239 if (feedback->event_type == feedback->POSE_UPDATE) {
241 double clamped_scale = std::min(std::max(cylinder_.controls.at(0).markers.at(0).scale.x + 2*(feedback->pose.position.y - controls_position_old_.position.y), 0.01), 0.05);
242 cylinder_.controls.at(0).markers.at(0).scale.x = clamped_scale;
243 cylinder_.controls.at(0).markers.at(0).scale.y = clamped_scale;
244 interactive_commands_server_->insert(cylinder_);
245 interactive_commands_server_->applyChanges();
247 double displacement_position =
computeAngularDistance(feedback->pose.orientation, controls_position_old_.orientation);
249 if (std::abs(displacement_position) > 1.5) {
250 interactive_commands_server_->erase(controls_.name);
251 interactive_commands_server_->applyChanges();
253 interactive_commands_server_->applyChanges();
256 double displacement_stiffness =
computeLinearDistance(feedback->pose.position, controls_position_old_.position);
258 joint_command_pub_.
publish(joint_command_trajectories_);
260 controls_position_old_ = feedback->pose;
264 if (feedback->event_type == feedback->MOUSE_UP) {
265 interactive_commands_server_->setPose(controls_.name, controls_position_orig_);
266 interactive_commands_server_->applyChanges();
278 double scaled_stiffness_value = 0.01 + stiffness_value*0.05;
279 cylinder_.controls.at(0).markers.at(0).scale.x = scaled_stiffness_value;
280 cylinder_.controls.at(0).markers.at(0).scale.y = scaled_stiffness_value;
281 interactive_commands_server_->insert(cylinder_);
282 interactive_commands_server_->applyChanges();
287 #endif // QB_MOVE_INTERACTIVE_INTERFACE_H void getRPY(tf2Scalar &roll, tf2Scalar &pitch, tf2Scalar &yaw, unsigned int solution_number=1) const
void publish(const boost::shared_ptr< M > &message) const
void setScaleFromStiffness(const double &stiffness_value)
Set the diameter scale of the marker from the given stiffness value.
visualization_msgs::InteractiveMarker cylinder_
void interactiveMarkerCallback(const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback)
This is the core method of the class, where commands are computed w.r.t.
ros::Publisher joint_command_pub_
ros::AsyncSpinner spinner_
void initMarkers(ros::NodeHandle &root_nh, const std::string &device_name, const std::vector< std::string > &joint_names)
Initialize the interactive_markers::InteractiveMarkerServer and the marker displayed in rviz to contr...
trajectory_msgs::JointTrajectory joint_command_trajectories_
void setMarkerState(const std::vector< double > &joint_positions)
Update the stored joint positions with the given values.
virtual ~qbMoveInteractive()
Stop the async spinner.
geometry_msgs::Pose controls_position_orig_
geometry_msgs::Pose controls_position_old_
A simple interface that adds an interactive marker (to be used in rviz) with two controls to change r...
double getStiffnessFromScale()
std::unique_ptr< interactive_markers::InteractiveMarkerServer > interactive_commands_server_
double computeAngularDistance(const geometry_msgs::Quaternion &to_pose, const geometry_msgs::Quaternion &from_pose)
Compute the angular distance between current and last orientations.
void fromMsg(const A &, B &b)
visualization_msgs::InteractiveMarker controls_
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
std::vector< std::string > joint_names_
std::vector< double > joint_positions_
double computeLinearDistance(const geometry_msgs::Point &to_pose, const geometry_msgs::Point &from_pose)
Compute the distance along the marker axis between current and last positions.
void buildMotorControl(visualization_msgs::InteractiveMarker &interactive_marker)
Add two interactive controls to the given interactive marker.
qbMoveInteractive()
Start the async spinner and do nothing else.
trajectory_msgs::JointTrajectory computeJointTrajectories(const double &displacement_position, const double &displacement_stiffness)
Compute a simple joint trajectory from the given displacements in position and orientation.
void buildCylinder(visualization_msgs::InteractiveMarker &interactive_marker)
Create a cylinder marker representing the qbmove shaft axis and attach it to the given interactive ma...