4 #ifndef MOTION_PLAYER_H
5 #define MOTION_PLAYER_H
7 #include <robotcontrol/model/robotmodel.h>
8 #include <robotcontrol/motionmodule.h>
9 #include <robotcontrol/FadeTorqueAction.h>
11 #include "boost/filesystem/operations.hpp"
12 #include "boost/filesystem/path.hpp"
13 #include "boost/progress.hpp"
14 #include "boost/regex.hpp"
16 #include <actionlib/client/simple_action_client.h>
18 #include <motion_player/PlayMotion.h>
19 #include <motion_player/StreamMotion.h>
20 #include <motion_player/DumpMotions.h>
22 #include <keyframe_player/KeyframePlayer.h>
23 #include <motion_file/motionfile.h>
24 #include <plot_msgs/plot_manager.h>
25 #include <ros/timer.h>
26 #include <Interpolator.hpp>
28 #include <std_srvs/Empty.h>
30 #include <motion_file/ruleapplier.h>
32 namespace motionplayer
35 class MappedMotion:
public motionfile::Motion
38 std::vector<int> motionToModel;
39 robotcontrol::RobotModel::State reqState;
40 robotcontrol::RobotModel::State transState;
41 robotcontrol::RobotModel::State resState;
43 std::vector<kf_player::KeyframePlayer> player;
45 MappedMotion(
const MappedMotion& _in) :
46 motionfile::Motion(_in)
48 reqState = _in.reqState;
49 transState = _in.transState;
50 resState = _in.resState;
51 motionToModel = _in.motionToModel;
60 MappedMotion& operator=(MappedMotion _in)
64 motionfile::Motion::operator=(_in);
65 reqState = _in.reqState;
66 transState = _in.transState;
67 resState = _in.resState;
68 motionToModel = _in.motionToModel;
78 class MotionPlayer :
public robotcontrol::MotionModule
81 typedef boost::shared_ptr<config_server::Parameter<float> > FloatParamPtr;
82 typedef boost::shared_ptr<config_server::Parameter<bool> > BoolParamPtr;
85 virtual ~MotionPlayer() {}
87 virtual bool init(robotcontrol::RobotModel* model);
89 virtual bool isTriggered();
92 std::map<std::string, MappedMotion> m_motionNames;
93 std::map<std::string, std::vector<FloatParamPtr> > m_ruleParameters;
94 BoolParamPtr m_limit_inverse_space;
95 FloatParamPtr m_epsion;
97 MappedMotion m_playingMotion;
99 motionfile::RuleApplier m_ruleApplier;
101 robotcontrol::RobotModel* m_model;
104 boost::shared_ptr<const urdf::Link> m_leftFootLink;
105 boost::shared_ptr<const urdf::Link> m_rightFootLink;
107 ros::ServiceServer m_srv_play;
108 ros::ServiceServer m_srv_update;
109 ros::ServiceServer m_srv_reload;
110 ros::ServiceServer m_srv_dump_motions;
112 std::vector<double> m_cmdPositions;
113 std::vector<double> m_cmdVelocities;
114 std::vector<double> m_cmdAccelerations;
115 std::vector<double> m_cmdEffort;
118 std::vector<kf_player::gainSelectEnum> m_preGains;
120 Eigen::Vector3f m_preAngle;
121 std::vector<double> m_integralGains;
124 actionlib::SimpleActionClient<robotcontrol::FadeTorqueAction> m_torqueAct;
127 robotcontrol::RobotModel::State m_state_relaxed;
128 robotcontrol::RobotModel::State m_state_setting_pose;
129 robotcontrol::RobotModel::State m_state_init;
130 robotcontrol::RobotModel::State m_state_standing;
131 robotcontrol::RobotModel::State m_state_sitting;
132 robotcontrol::RobotModel::State m_state_falling;
133 robotcontrol::RobotModel::State m_state_lying_prone;
134 robotcontrol::RobotModel::State m_state_lying_supine;
135 static const std::string m_fallingStatePrefix;
138 std::string m_robot_name;
139 std::string m_robot_type;
142 std::string m_init_pose_name;
143 std::string m_init_name;
144 std::string m_getup_prone_name;
145 std::string m_getup_supine_name;
148 ros::Publisher statePublisher;
150 bool handlePlay(motion_player::PlayMotionRequest& req, motion_player::PlayMotionResponse& res);
151 bool handleUpdateMotion(motion_player::StreamMotionRequest& req, motion_player::StreamMotionResponse& res);
152 bool handleReloadMotion(std_srvs::Empty::Request& req, std_srvs::Empty::Response& res);
153 bool handleDumpMotions(motion_player::DumpMotionsRequest& req, motion_player::DumpMotionsResponse& res);
155 bool tryToPlay(
const std::string& motion,
bool checkState =
true);
156 void play(
const std::string& motion);
160 bool m_isInitialized;
163 inline void startPlaying() { isPlaying =
true; };
164 inline void stopPlaying() { isPlaying =
false; };
166 void writeCommands();
169 void initRuleParameters();
171 void applyRule(motionplayer::MappedMotion &motion,
int rule_id,
const float delta);
173 void publishState(
const ros::TimerEvent& event);
175 bool loadMotionFiles(
const boost::filesystem::path& dir);
176 bool reloadMotionFiles(
const boost::filesystem::path& dir);
177 int findIndex(std::string name);
193 plot_msgs::PlotManagerFS PM;