10 #include <robotcontrol/motionmodule.h>
11 #include <robotcontrol/model/robotmodel.h>
12 #include <rc_utils/math_spline.h>
13 #include <config_server/parameter.h>
14 #include <plot_msgs/plot_manager.h>
15 #include <pluginlib/class_loader.h>
16 #include <boost/shared_ptr.hpp>
17 #include <boost/make_shared.hpp>
20 #include <gait/gait_common.h>
21 #include <gait/gait_command.h>
22 #include <gait/gait_engine.h>
25 #include <tf/transform_broadcaster.h>
26 #include <gait_msgs/GaitCommand.h>
27 #include <gait_msgs/GaitOdom.h>
28 #include <gait_msgs/SetOdom.h>
29 #include <sensor_msgs/Joy.h>
30 #include <diagnostic_msgs/DiagnosticArray.h>
31 #include <std_srvs/Empty.h>
34 #include <ros/subscriber.h>
54 class Gait :
public robotcontrol::MotionModule
62 virtual bool init(robotcontrol::RobotModel* model);
65 virtual bool isTriggered();
71 virtual void publishTransforms();
75 const std::string&
gaitName()
const {
return m_gaitName; }
79 const std::string CONFIG_PARAM_PATH;
82 boost::shared_ptr<config_server::Parameter<bool> > m_enableGait;
83 config_server::Parameter<bool> m_enableJoystick;
84 config_server::Parameter<bool> m_plotData;
85 config_server::Parameter<bool> m_publishOdometry;
86 config_server::Parameter<bool> m_publishTransforms;
87 config_server::Parameter<float> m_gcvNormP;
88 config_server::Parameter<float> m_gcvNormMax;
89 config_server::Parameter<float> m_gcvZeroTime;
90 config_server::Parameter<float> m_minWalkingTime;
93 robotcontrol::RobotModel* m_model;
94 int m_jointMap[NUM_JOINTS];
95 boost::shared_ptr<const urdf::Link> m_trunkLink;
96 boost::shared_ptr<const urdf::Link> m_leftFootLink;
97 boost::shared_ptr<const urdf::Link> m_rightFootLink;
105 robotcontrol::RobotModel::State m_state_standing;
106 robotcontrol::RobotModel::State m_state_walking;
109 std::string m_gaitName;
115 void updateTransforms();
118 boost::shared_ptr<GaitEngine> m_engine;
119 pluginlib::ClassLoader<GaitEngine> m_enginePluginLoader;
120 bool loadGaitEngine();
121 void updateHaltPose();
125 void setSupportCoefficients(
double leftLegCoeff,
double rightLegCoeff);
132 ros::Subscriber m_sub_gaitCommand;
133 void handleGaitCommand(
const gait_msgs::GaitCommandConstPtr& cmd);
134 void plotRawGaitCommand();
137 void setPendingMotion(
MotionID ID,
MotionStance stance = STANCE_DEFAULT,
bool adjustLeft =
true,
bool adjustRight =
true);
138 void clearPendingMotion();
142 bool m_motionAdjustLeftFoot;
143 bool m_motionAdjustRightFoot;
146 rc_utils::TrapVelSpline m_jointSpline[NUM_JOINTS];
147 rc_utils::LinearSpline m_jointEffortSpline[NUM_JOINTS];
148 ros::Time m_reachStartTime;
149 ros::Time m_lastHaltTime;
150 double m_reachDuration;
153 void startReachHaltPose();
154 void continueReachHaltPose();
155 void stopReachHaltPose();
158 static const int GAIT_BUTTONS = 4;
159 static const int MISC_BUTTONS = 8;
160 static const int JOY_BUTTONS = GAIT_BUTTONS + MISC_BUTTONS;
161 bool m_joystickEnabled;
162 bool m_joystickConnected;
163 bool m_joystickGaitCmdLock;
164 bool m_joystickButtonPressed[JOY_BUTTONS];
165 bool m_joystickButtonTriggered[MISC_BUTTONS];
166 ros::Subscriber m_sub_joystickData;
167 ros::Subscriber m_sub_joystickStatus;
168 void handleJoystickButtons();
169 void handleJoystickData(
const sensor_msgs::JoyConstPtr& joy);
170 void handleJoystickStatus(
const diagnostic_msgs::DiagnosticArrayConstPtr& array);
171 void setJoystickGaitCmdLock(
bool lock);
172 void callbackEnableJoystick();
175 tf::TransformBroadcaster m_tf_broadcaster;
176 std::vector<tf::StampedTransform> m_tf_transforms;
177 tf::StampedTransform* m_tf_ego_floor;
178 tf::StampedTransform* m_tf_odom;
179 gait_msgs::GaitOdom m_gait_odom;
180 ros::Publisher m_pub_odom;
181 void configureTransforms();
184 ros::ServiceServer m_srv_resetOdom;
185 ros::ServiceServer m_srv_setOdom;
186 bool handleResetOdometry(std_srvs::EmptyRequest& req, std_srvs::EmptyResponse& res);
187 bool handleSetOdometry(gait_msgs::SetOdomRequest &req, gait_msgs::SetOdomResponse &res);
190 bool constructJointMap();
196 GS_REACHING_HALT_POSE,
201 GaitState m_gaitState;
203 void plotGaitStateEvent();
206 plot_msgs::PlotManagerFS m_PM;
207 void configurePlotManager();
208 void callbackPlotData();
213 PM_GAITCMD_LIN_VEL_X,
214 PM_GAITCMD_LIN_VEL_Y,
215 PM_GAITCMD_ANG_VEL_Z,
218 PM_JOINTCMD_LAST = PM_JOINTCMD_FIRST + NUM_JOINTS - 1,
219 PM_JOINTEFFORT_FIRST,
220 PM_JOINTEFFORT_LAST = PM_JOINTEFFORT_FIRST + NUM_JOINTS - 1,
221 PM_USE_RAW_JOINT_CMDS,
223 PM_LEFT_SUPPORT_COEFF,
224 PM_RIGHT_SUPPORT_COEFF,
225 PM_GAITCMDRAW_LIN_VEL_X,
226 PM_GAITCMDRAW_LIN_VEL_Y,
227 PM_GAITCMDRAW_ANG_VEL_Z,
Generic gait motion module that can execute a given GaitEngine.
Definition: gait.h:54
MotionID
Enumeration of motion IDs that can be used in the GaitCommand::motion field to trigger motions throug...
Definition: gait_common.h:85
Gait command data structure.
Definition: gait_command.h:20
Data struct for passing gait engine output data from the gait engine to the generic gait motion modul...
Definition: gait_interface.h:68
MotionStance
Enumeration of motion stances that can be commanded to a gait engine.
Definition: gait_common.h:107
const std::string & gaitName() const
Retrieve the name of the gait (e.g. if the parameter string is cpg_gait::CPGGait then the gait name i...
Definition: gait.h:75
virtual ~Gait()
Destructor.
Definition: gait.cpp:87
Gait()
Default constructor.
Definition: gait.cpp:37