TrajectoryManager.h
Go to the documentation of this file.
00001 
00006 #ifndef TRAJECTORYMANAGER_H
00007 #define TRAJECTORYMANAGER_H
00008 
00009 #include "robodyn_controllers/JointTrajectoryManager.h"
00010 #include "robodyn_utilities/GoalStatusSender.h"
00011 #include <sensor_msgs/JointState.h>
00012 #include <boost/ptr_container/ptr_map.hpp>
00013 #include "robodyn_controllers/JointTrajectoryFollower.h"
00014 #include "r2_msgs/PoseTrajectory.h"
00015 #include "r2_msgs/ControllerPoseSettings.h"
00016 #include "r2_msgs/PoseState.h"
00017 #include "r2_msgs/StringArray.h"
00018 #include "robodyn_controllers/MobileTreeIk.h"
00019 #include "robodyn_controllers/TrapezoidalVelocityTrajectoryFactory.h"
00020 #include "robodyn_controllers/RosMsgTrajectoryFactory.h"
00021 #include "robodyn_controllers/RosMsgTreeIkTrajectoryFactory.h"
00022 #include "robodyn_controllers/RosMsgForceTrajectoryFactory.h"
00023 #include "r2_msgs/JointCommand.h"
00024 #include "r2_msgs/JointControlDataArray.h"
00025 #include "r2_msgs/ReplanType.h"
00026 #include "robodyn_controllers/MotionLimiter.h"
00027 #include "r2_msgs/JointCapability.h"
00028 #include "r2_msgs/ForceControlAxis.h"
00029 #include "r2_msgs/WrenchState.h"
00030 #include "r2_msgs/ForceControlAxisArray.h"
00031 #include "r2_msgs/ToolFrame.h"
00032 #include "robodyn_controllers/RosMsgToolFrameManager.h"
00033 
00034 #include <iostream>
00035 #include <string>
00036 
00041 class TrajectoryManager : public JointTrajectoryManager, public GoalStatusSender
00042 {
00043 public:
00044     TrajectoryManager(const std::string& name);
00045 
00046     virtual ~TrajectoryManager();
00047 
00048     struct ForceGains
00049     {
00050       double filterAlpha;
00051       double forceGain;
00052       double torqueGain;
00053       double forceIntegral;
00054       double torqueIntegral;
00055       double forceDamping;
00056       double torqueDamping;
00057       double forceWindupLimit;
00058       double torqueWindupLimit;
00059       double positionErrorLimit;
00060       double rotationErrorLimit;
00061       bool doFeedForward;
00062 
00063       ForceGains()
00064       {
00065         filterAlpha = 0.9;
00066         forceGain = torqueGain = 2.0;
00067         forceIntegral = torqueIntegral = 0.0;
00068         forceDamping = torqueDamping = 0.2;
00069         forceWindupLimit = torqueWindupLimit = 0;
00070         positionErrorLimit = rotationErrorLimit = 0.02;
00071         doFeedForward = false;
00072       }
00073     };
00074 
00075     void initialize(const std::string& urdfFile, double timeStep_in);
00076     void initialize_sim(const std::string& urdfDesc, double timeStepIn);
00077     void updateTree(const r2_msgs::ToolFrame& toolFrameMsg);
00078 
00079     void updateTrajectories(const r2_msgs::JointCommand& defaultCommandMsg, const r2_msgs::JointControlDataArray& defaultControlMsg, const sensor_msgs::JointState& startJointPositions, const sensor_msgs::JointState& startJointVels);
00080     void updateSensorForces(const r2_msgs::WrenchState& wrenchSensors);
00081     void updateActualPoseState(const r2_msgs::PoseState& actualPoseState);
00082     void updateInertia(const sensor_msgs::JointState& inertia_in);
00083 
00084     void setJointSettings(const r2_msgs::ControllerJointSettings& settingsMsg);
00085     void getJointSettings(r2_msgs::ControllerJointSettings& settingsMsg);
00086     void setPoseSettings(const r2_msgs::ControllerPoseSettings& settingsMsg);
00087     void setJointCapabilities(const r2_msgs::JointCapability& capabilitiesMsg);
00088     void setBases(const r2_msgs::StringArray& basesMsg);
00089     void setVelocityFactor(double velocityFactor_in) {velocityFactor = velocityFactor_in;}
00090     void setPriorityTol(std::vector<double> priorityNum, std::vector<double> priorityLinearTol, std::vector<double> priorityAngularTol);
00091     void setIkParameters(double mBar, double kr, unsigned int maxIts, double maxTwist);
00092     void setSensorNameMap(std::vector<std::string> sensorKeys, std::vector<std::string> sensorNames);
00093     void setForceParameters(struct ForceGains new_gains);
00094 
00106     double addForceWaypoints(const r2_msgs::PoseTrajectory& trajectory,
00107                              const sensor_msgs::JointState& startJointPositions,
00108                              const sensor_msgs::JointState& startJointVels,
00109                              const sensor_msgs::JointState& prevJointVels,
00110                              const r2_msgs::PoseState& startPoseState,
00111                              const r2_msgs::PoseState& startPoseVels,
00112                              const r2_msgs::ForceControlAxisArray& forceAxes);
00113     double addCartesianWaypoints(const r2_msgs::PoseTrajectory& trajectory,
00114                                  const sensor_msgs::JointState& startJointPositions,
00115                                  const sensor_msgs::JointState& startJointVels,
00116                                  const sensor_msgs::JointState& prevJointVels,
00117                                  const r2_msgs::PoseState& startPoseState,
00118                                  const r2_msgs::PoseState& startPoseVels);
00119     void addJointWaypoints(const trajectory_msgs::JointTrajectory& trajectory,
00120                            const sensor_msgs::JointState& startJointPositions,
00121                            const sensor_msgs::JointState& startJointVels,
00122                            const sensor_msgs::JointState& prevJointVels,
00123                            const std::vector<r2_msgs::ReplanType>& replanVec = std::vector<r2_msgs::ReplanType>());
00124     void addJointBreadcrumbs(const trajectory_msgs::JointTrajectory& trajectory);
00125 
00126 protected:
00127     virtual void writeJointState(const sensor_msgs::JointState& jointState_out) = 0;
00128     virtual void writeJointControl(const r2_msgs::JointControlDataArray& jointControl_out) = 0;
00129 
00130     bool isActive(const actionlib_msgs::GoalID& goalId) const;
00131 
00132     // helper functions
00133     void abort(const actionlib_msgs::GoalID& goalId, const std::string& msg = std::string()); // abort if active
00134     void abort(const actionlib_msgs::GoalID& goalId, std::set<std::string>& abortedJoints, const std::string& msg = std::string()); // abort if active and return joint names aborted
00135     void preempt(const std::vector<std::string>& jointNames, std::set<std::string>& preemptedJoints, const std::string& msg = std::string()); // preempt if joint being used
00136     void resetAll(const std::string& msg = std::string());
00137     // kasquish is a smooth stop
00138     void kasquish(const std::vector<std::string>& jointNames,
00139                   const sensor_msgs::JointState& startJointPositions,
00140                   const sensor_msgs::JointState& startJointVels);
00141     void kasquishAll(const sensor_msgs::JointState& startJointPositions,
00142                      const sensor_msgs::JointState& startJointVels, const std::string& msg = std::string());
00143 
00144     std::string sensor;
00145 
00146     double velocityFactor;
00147     double timeStep;
00148     double stopVelocityLimit;
00149     double stopAccelerationLimit;
00150     double zeroLimit;
00151     ros::Duration timestep_in;
00152 
00153     bool jointSettingsValid, poseSettingsValid, basesValid;
00154 
00155 
00156 private:
00157     struct GoalIdCompare : public std::binary_function<actionlib_msgs::GoalID, actionlib_msgs::GoalID, bool>
00158     {
00159         bool operator()(const actionlib_msgs::GoalID& left, const actionlib_msgs::GoalID& right) const
00160         {
00161             return (left.stamp < right.stamp || (left.stamp == right.stamp && left.id < right.id));
00162         }
00163     };
00164 
00165     // output
00166     sensor_msgs::JointState jointStateOut;
00167     r2_msgs::JointControlDataArray   jointControlOut;
00168 
00169     // trajectory helpers
00170     typedef TrapezoidalVelocityJointTrajectoryFactory jointTrajFactory_type;
00171     typedef TrapezoidalVelocitySynchedCartesianTrajectoryFactory cartTrajFactory_type;
00172     boost::shared_ptr<jointTrajFactory_type> jointTrajFactory;
00173     boost::shared_ptr<cartTrajFactory_type> cartTrajFactory;
00174     RosMsgJointTrajectoryFactory rosJointTrajFactory;
00175     RosMsgCartesianTrajectoryFactory rosCartTrajFactory;
00176     RosMsgTreeIkTrajectoryFactory rosTreeIkTrajFactory;
00177     RosMsgForceTrajectoryFactory rosForceTrajFactory;
00178     r2_msgs::ControllerJointSettings jointSettings;
00179     boost::shared_ptr<JointNamePositionLimiter> positionLimiter;
00180 
00181     // other helpers
00182     std::map<std::string, unsigned int> jointIndexMap;
00183     boost::shared_ptr<MobileTreeIk> treeIkPtr;
00184     boost::shared_ptr<Cartesian_HybCntrl> forceController;
00185     std::map<std::string, bool> controllableJoints;
00186     std::map<std::string, double> jointInertiaMap;
00187     std::map<std::string, KDL::Wrench> forceSensorMap;
00188     std::vector<std::string> actualFrameNames;
00189     std::map<std::string, KDL::FrameVel> actualFrameVelMap;
00190 
00191     RosMsgToolFrameManager toolFrameManager;
00192 
00193     // keep track of goals
00194     typedef boost::ptr_map<actionlib_msgs::GoalID, JointTrajectoryFollower, GoalIdCompare> GoalFollowerMap_type;
00195     GoalFollowerMap_type goalFollowerMap;
00196     typedef std::map<actionlib_msgs::GoalID, actionlib_msgs::GoalStatus, GoalIdCompare> GoalStatusMap_type;
00197     GoalStatusMap_type goalStatusMap;
00198     typedef std::map<actionlib_msgs::GoalID, std::vector<r2_msgs::ReplanType>, GoalIdCompare> GoalReplanMap_type;
00199     GoalReplanMap_type goalReplanMap;
00200 
00201     void setupJointState(const r2_msgs::JointCommand& jointCommand);
00202     void setupJointControl(const r2_msgs::JointControlDataArray& jointControl);
00203 };
00204 
00205 #endif


robodyn_controllers
Author(s):
autogenerated on Sat Jun 8 2019 20:20:53