Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include <hrl_kinematics/TestStability.h>
00033 #include <ros/ros.h>
00034
00035
00036 namespace hrl_kinematics {
00037
00043 class TestStabilityNode {
00044 public:
00045 TestStabilityNode(Kinematics::FootSupport support = Kinematics::SUPPORT_DOUBLE);
00046 TestStabilityNode(ros::NodeHandle _nh_, TestStability _test_stability_, Kinematics::FootSupport support);
00047 virtual ~TestStabilityNode();
00048 void initialize();
00049 void jointStateCb(const sensor_msgs::JointStateConstPtr& state);
00050
00051 protected:
00052 ros::NodeHandle nh_;
00053 ros::Subscriber joint_state_sub_;
00054 ros::Publisher visualization_pub_, support_polygon_pub_, pcom_pub_;
00055 TestStability test_stability_;
00056 Kinematics::FootSupport support_mode_;
00057 };
00058
00059 TestStabilityNode::TestStabilityNode(ros::NodeHandle _nh_, TestStability _test_stability_, Kinematics::FootSupport support)
00060 : nh_(_nh_), test_stability_(_test_stability_), support_mode_ (support)
00061 {
00062 initialize();
00063 }
00064
00065 TestStabilityNode::TestStabilityNode(Kinematics::FootSupport support)
00066 : support_mode_(support)
00067 {
00068 initialize();
00069 }
00070
00071 TestStabilityNode::~TestStabilityNode(){
00072
00073 }
00074
00075 void TestStabilityNode::initialize()
00076 {
00077 ros::NodeHandle nh_private("~");
00078 visualization_pub_ = nh_private.advertise<visualization_msgs::MarkerArray>("stability_visualization", 1);
00079 support_polygon_pub_ = nh_private.advertise<geometry_msgs::PolygonStamped>("support_polygon", 10);
00080 pcom_pub_ = nh_private.advertise<visualization_msgs::Marker>("projected_com", 10);
00081
00082 joint_state_sub_ = nh_.subscribe("joint_states", 1, &TestStabilityNode::jointStateCb, this);
00083 }
00084
00085 void TestStabilityNode::jointStateCb(const sensor_msgs::JointStateConstPtr& state){
00086 size_t num_joints = state->position.size();
00087 ROS_DEBUG("Received JointState with %zu joints", num_joints);
00088
00089
00090
00091
00092 std::map<std::string, double> joint_positions;
00093 for (unsigned int i=0; i<state->name.size(); i++)
00094 joint_positions.insert(make_pair(state->name[i], state->position[i]));
00095
00096 tf::Vector3 normal_vector(0.0, 0.0, 1.0);
00097
00098
00099 normal_vector.normalize();
00100
00101 bool stable = test_stability_.isPoseStable(joint_positions, support_mode_, normal_vector);
00102
00103
00104 tf::Point com = test_stability_.getCOM();
00105 if (stable)
00106 ROS_INFO("Pose is stable, pCOM at %f %f", com.x(), com.y());
00107 else
00108 ROS_INFO("Pose is NOT stable, pCOM at %f %f", com.x(), com.y());
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124 support_polygon_pub_.publish(test_stability_.getSupportPolygon());
00125 pcom_pub_.publish(test_stability_.getCOMMarker());
00126
00127 }
00128
00129
00130 }
00131
00132 using namespace hrl_kinematics;
00133
00134 int main(int argc, char** argv)
00135 {
00136 ros::init(argc, argv, "test_stability");
00137
00138 Kinematics::FootSupport support = Kinematics::SUPPORT_DOUBLE;
00139
00140 if (argc == 2){
00141 int i = atoi(argv[1]);
00142 if (i >= 0 && i <= 2)
00143 support = Kinematics::FootSupport(i);
00144
00145 }
00146
00147 try
00148 {
00149 ros::spinOnce();
00150
00151 ros::NodeHandle nh_;
00152 std::string root_link_name_, rfoot_link_name_, lfoot_link_name_, rfoot_mesh_link_name_;
00153 if (!nh_.getParam("test_stability/root_link_name", root_link_name_))
00154 root_link_name_ = "base_link";
00155 if (!nh_.getParam("test_stability/rfoot_link_name", rfoot_link_name_))
00156 rfoot_link_name_ = "r_sole";
00157 if (!nh_.getParam("test_stability/lfoot_link_name", lfoot_link_name_))
00158 lfoot_link_name_ = "l_sole";
00159 if (!nh_.getParam("test_stability/rfoot_mesh_link_name", rfoot_mesh_link_name_))
00160 rfoot_mesh_link_name_ = "RAnkleRoll_link";
00161
00162 hrl_kinematics::TestStability test_stability_(root_link_name_, rfoot_link_name_, lfoot_link_name_, rfoot_mesh_link_name_);
00163 hrl_kinematics::TestStabilityNode StabilityNode(nh_, test_stability_, support);
00164
00165
00166 ros::spin();
00167 }
00168 catch(hrl_kinematics::Kinematics::InitFailed &e)
00169 {
00170 std::cerr << "Could not initialize kinematics node: " << e.what() << std::endl;
00171
00172
00173 return 1;
00174 }
00175
00176 return 0;
00177
00178 }
00179