qb_delta_kinematic_controller.h
Go to the documentation of this file.
1 /***
2  * Software License Agreement: BSD 3-Clause License
3  *
4  * Copyright (c) 2016-2018, qbrobotics®
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
8  * following conditions are met:
9  *
10  * * Redistributions of source code must retain the above copyright notice, this list of conditions and the
11  * following disclaimer.
12  *
13  * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
14  * following disclaimer in the documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote
17  * products derived from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
25  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #ifndef QB_CHAIN_CONTROLLERS_H
29 #define QB_CHAIN_CONTROLLERS_H
30 
31 // Standard libraries
32 #include <regex>
33 
34 // ROS libraries
36 #include <control_msgs/FollowJointTrajectoryAction.h>
38 #include <geometry_msgs/PointStamped.h>
42 #include <sensor_msgs/JointState.h>
44 #include <tf2/utils.h>
46 #include <trajectory_msgs/JointTrajectory.h>
47 
48 // internal libraries
49 
58 class DeltaKinematicController : public controller_interface::Controller<hardware_interface::PositionJointInterface> {
59  public:
65 
69  ~DeltaKinematicController() override;
70 
81  bool init(hardware_interface::PositionJointInterface *robot_hw, ros::NodeHandle &root_nh, ros::NodeHandle &controller_nh) override;
82 
87  void starting(const ros::Time &time) override {}
88 
93  void stopping(const ros::Time &time) override {}
94 
100  void update(const ros::Time &time, const ros::Duration &period) override;
101 
102  protected:
111 
112  std::unique_ptr<interactive_markers::InteractiveMarkerServer> interactive_commands_server_;
113  visualization_msgs::InteractiveMarker controls_;
114  geometry_msgs::Point feedback_position_old_;
116 
117  std::vector<std::string> motor_names_;
118  std::map<std::string, std::unique_ptr<actionlib::SimpleActionClient<control_msgs::FollowJointTrajectoryAction>>> motor_action_clients_;
119  std::map<std::string, hardware_interface::JointHandle> motor_joints_;
120  std::map<std::string, std::vector<std::string>> motor_joint_names_;
121  std::map<std::string, trajectory_msgs::JointTrajectory> motor_joint_trajectories_;
122  geometry_msgs::Point ee_offset_;
123 
126  std::string waypoint_namespace_;
129  std::vector<double> filter_param_a_;
130  std::vector<double> filter_param_b_;
131 
136  void actionActiveCallback(const std::string &controller);
137 
145  void actionDoneCallback(const actionlib::SimpleClientGoalState &state, const control_msgs::FollowJointTrajectoryResultConstPtr &result, const std::string &controller);
146 
152  void actionFeedbackCallback(const control_msgs::FollowJointTrajectoryFeedbackConstPtr &feedback, const std::string &controller);
153 
160  void buildCube(visualization_msgs::InteractiveMarker &interactive_marker);
161 
168  void buildEndEffectorControl(visualization_msgs::InteractiveMarker &interactive_marker);
169 
179  bool cartesianLinearPlanner(const geometry_msgs::Point &target_pose, std::vector<std::vector<double>> &joint_positions);
180 
187  double computeDistance(const geometry_msgs::Point &from_pose, const geometry_msgs::Point &to_pose);
188 
196  std::vector<geometry_msgs::Point> computeIntermediatePosesTo(const geometry_msgs::Point &target_pose);
197 
206  std::vector<std::vector<double>> computeIntermediateStiffnessesTo(const std::vector<double> &target_joint_stiffnesses, const int &size);
207 
217  std::map<std::string, trajectory_msgs::JointTrajectory> computeJointTrajectories(const std::vector<std::vector<double>> &motor_positions, const std::vector<std::vector<double>> &motor_stiffness, const double &target_time_from_start, const double &previous_time_from_start);
218 
227  bool deltaStatePublisher(const std::vector<double> &motor_joints, const geometry_msgs::Point &ee_pose);
228 
234  void fillMotorJointTrajectories(const std::map<std::string, trajectory_msgs::JointTrajectory> &motor_joint_trajectories);
235 
243  void filter(const std::vector<double> &b, const std::vector<double> &a, const std::vector<double> &x, std::vector<double> &y);
244 
251  void filterMotorJointTrajectories(const std::vector<double> &b, const std::vector<double> &a);
252 
261  void filterMotorJointTrajectory(const std::vector<double> &b, const std::vector<double> &a, trajectory_msgs::JointTrajectory &motor_joint_trajectory);
262 
270  bool forwardKinematics(const std::vector<double> &joint_positions, geometry_msgs::Point &ee_pose);
271 
275  std::string getMotorName(const int &id);
276 
280  double getMotorPosition(const int &id);
281 
285  std::vector<double> getMotorPositions();
286 
290  double getMotorStiffness(const int &id);
291 
295  std::vector<double> getMotorStiffnesses();
296 
300  std::vector<std::string> getMotorJointNames(const int &id);
301 
305  trajectory_msgs::JointTrajectory getMotorJointTrajectory(const int &id);
306 
310  std::vector<double> getTrajectoryLastPositions();
311 
315  std::vector<double> getTrajectoryLastStiffnesses();
316 
321 
328  void initMarkers();
329 
337  void interactiveMarkerCallback(const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback);
338 
346  bool inverseKinematics(const geometry_msgs::Point &ee_pose, std::vector<double> &joint_positions);
347 
355  void move(const trajectory_msgs::JointTrajectory &joint_trajectory, const std::string &motor);
356 
362  void move();
363 
373  bool parseVector(const XmlRpc::XmlRpcValue &xml_value, const int &size, std::vector<double> &vector);
374 
390  void parseWaypointTrajectory(ros::NodeHandle &node_handle);
391 
406  void targetPosesCallback(const geometry_msgs::PointStamped &msg);
407 
417  template<class T>
418  T xmlCast(XmlRpc::XmlRpcValue xml_value);
419 };
420 } // namespace qb_chain_controllers
421 
422 #endif // QB_CHAIN_CONTROLLERS_H
std::vector< geometry_msgs::Point > computeIntermediatePosesTo(const geometry_msgs::Point &target_pose)
Compute a linear-in-space interpolation from the last computed value to the given target end-effector...
void update(const ros::Time &time, const ros::Duration &period) override
Update the delta state.
std::map< std::string, std::vector< std::string > > motor_joint_names_
void initMarkers()
Initialize the interactive_markers::InteractiveMarkerServer and the marker displayed in rviz to contr...
double computeDistance(const geometry_msgs::Point &from_pose, const geometry_msgs::Point &to_pose)
Compute the absolute 3D distance between the given points.
void buildCube(visualization_msgs::InteractiveMarker &interactive_marker)
Create a cubic marker which can be moved interactively in all the Cartesian space.
void actionDoneCallback(const actionlib::SimpleClientGoalState &state, const control_msgs::FollowJointTrajectoryResultConstPtr &result, const std::string &controller)
Restart the waypoint trajectory automatically if waypoints have been retrieved during the initializat...
std::unique_ptr< interactive_markers::InteractiveMarkerServer > interactive_commands_server_
bool cartesianLinearPlanner(const geometry_msgs::Point &target_pose, std::vector< std::vector< double >> &joint_positions)
Compute the joint trajectory of all the upper motors from the last computed value to the given target...
std::vector< std::string > getMotorJointNames(const int &id)
bool deltaStatePublisher(const std::vector< double > &motor_joints, const geometry_msgs::Point &ee_pose)
Compute all the free joint positions (i.e.
void filterMotorJointTrajectories(const std::vector< double > &b, const std::vector< double > &a)
Filter all the trajectories stored in the joint trajectories private map.
void interactiveMarkerCallback(const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback)
If waypoints are not used, this become the core method of the class, where commands are computed w...
DeltaKinematicController()
Start the async spinner and do nothing else.
bool init(hardware_interface::PositionJointInterface *robot_hw, ros::NodeHandle &root_nh, ros::NodeHandle &controller_nh) override
The init function is called to initialize the controller from a non-realtime thread with a pointer to...
void buildEndEffectorControl(visualization_msgs::InteractiveMarker &interactive_marker)
Add six distinct interactive controls to the given interactive marker.
std::map< std::string, trajectory_msgs::JointTrajectory > computeJointTrajectories(const std::vector< std::vector< double >> &motor_positions, const std::vector< std::vector< double >> &motor_stiffness, const double &target_time_from_start, const double &previous_time_from_start)
Compute a segment of trajectories for all the upper motors from the given parameters.
void filterMotorJointTrajectory(const std::vector< double > &b, const std::vector< double > &a, trajectory_msgs::JointTrajectory &motor_joint_trajectory)
Filter the given joint trajectory, by considering the whole data as a vector of new measurements (eac...
T xmlCast(XmlRpc::XmlRpcValue xml_value)
Cast an XmlRpcValue from TypeDouble, TypeInt or TypeBoolean to the specified template type...
void targetPosesCallback(const geometry_msgs::PointStamped &msg)
Call the Cartesian Planner to compute the joint trajectory from the current position of the end-effec...
std::vector< std::vector< double > > computeIntermediateStiffnessesTo(const std::vector< double > &target_joint_stiffnesses, const int &size)
Compute the linearized trajectory from the last computed value to the given target joint stiffness of...
std::map< std::string, trajectory_msgs::JointTrajectory > motor_joint_trajectories_
void startWaypointTrajectory()
Parse all the waypoints, filter the whole generated joint trajectory and send the commands to the dev...
void actionFeedbackCallback(const control_msgs::FollowJointTrajectoryFeedbackConstPtr &feedback, const std::string &controller)
Do nothing apart from debug info.
bool parseVector(const XmlRpc::XmlRpcValue &xml_value, const int &size, std::vector< double > &vector)
Parse the given XmlRpcValue as a std::vector, since the XmlRpc::XmlRpcValue class does not handle thi...
std::map< std::string, hardware_interface::JointHandle > motor_joints_
bool inverseKinematics(const geometry_msgs::Point &ee_pose, std::vector< double > &joint_positions)
Compute the inverse kinematics of the delta device.
void fillMotorJointTrajectories(const std::map< std::string, trajectory_msgs::JointTrajectory > &motor_joint_trajectories)
Append the given trajectories to the joint trajectories private map.
void move()
Make all the calls to the Action Servers relative to all the trajectories previously parsed (either f...
This controller is made to simplify the usage and the user interaction with the delta device...
void actionActiveCallback(const std::string &controller)
Do nothing apart from debug info.
void parseWaypointTrajectory(ros::NodeHandle &node_handle)
Parse all the waypoints set up in the Parameter Server at <robot_namespace>/waypoints.
void starting(const ros::Time &time) override
This is called from within the realtime thread just before the first call to update.
void filter(const std::vector< double > &b, const std::vector< double > &a, const std::vector< double > &x, std::vector< double > &y)
Filter data following a discrete parametrization of the samples.
bool forwardKinematics(const std::vector< double > &joint_positions, geometry_msgs::Point &ee_pose)
Compute the forward kinematics of the delta device.
trajectory_msgs::JointTrajectory getMotorJointTrajectory(const int &id)
std::map< std::string, std::unique_ptr< actionlib::SimpleActionClient< control_msgs::FollowJointTrajectoryAction > > > motor_action_clients_
void stopping(const ros::Time &time) override
This is called from within the realtime thread just after the last update call before the controller ...


qb_chain_controllers
Author(s): qbrobotics®
autogenerated on Thu Jun 13 2019 19:33:39