helper.cpp
Go to the documentation of this file.
2 
4 {
5 msgs::ErrorStatus determineStartFeetPose(msgs::Feet& start_feet, ros::ServiceClient& generate_feet_pose_client, const std_msgs::Header& header)
6 {
7  msgs::ErrorStatus status;
8 
9  // get start feet pose
10  msgs::GenerateFeetPoseService feet_pose_service;
11  feet_pose_service.request.request.header = header;
12  feet_pose_service.request.request.flags = msgs::FeetPoseRequest::FLAG_CURRENT | msgs::FeetPoseRequest::FLAG_3D;
13 
14  if (!generate_feet_pose_client.call(feet_pose_service.request, feet_pose_service.response))
15  return ErrorStatusError(msgs::ErrorStatus::ERR_UNKNOWN, "determineStartFeetPose", "Can't call 'FeetPoseGenerator'!", true, 1.0);
16 
17  // check result
18  if (hasError(feet_pose_service.response.status))
19  {
20  //status += feet_pose_service.response.status;
21  status += ErrorStatusWarning(msgs::ErrorStatus::WARN_UNKNOWN, "determineStartFeetPose", "Can't obtain start feet pose; defaulting to origin.", true, 1.0);
22 
23  feet_pose_service.request.request.pose = geometry_msgs::Pose();
24  feet_pose_service.request.request.pose.orientation = tf::createQuaternionMsgFromYaw(0.0);
25  feet_pose_service.request.request.flags = msgs::FeetPoseRequest::FLAG_3D;
26 
27  if (!generate_feet_pose_client.call(feet_pose_service.request, feet_pose_service.response))
28  return ErrorStatusError(msgs::ErrorStatus::ERR_UNKNOWN, "determineStartFeetPose", "Can't call 'FeetPoseGenerator'!", true, 1.0);
29 
30  if (hasError(feet_pose_service.response.status))
31  {
32  status += feet_pose_service.response.status;
33  return status;
34  }
35  }
36  else if (hasWarning(feet_pose_service.response.status))
37  status += feet_pose_service.response.status;
38 
39  start_feet = feet_pose_service.response.feet;
40  return status;
41 }
42 
43 msgs::ErrorStatus determineGoalFeetPose(msgs::Feet& goal_feet, ros::ServiceClient& generate_feet_pose_client, const geometry_msgs::PoseStamped& goal_pose)
44 {
45  msgs::GenerateFeetPoseService feet_pose_service;
46  feet_pose_service.request.request.header = goal_pose.header;
47  feet_pose_service.request.request.pose = goal_pose.pose;
48  feet_pose_service.request.request.flags = msgs::FeetPoseRequest::FLAG_3D;
49 
50  if (!generate_feet_pose_client.call(feet_pose_service.request, feet_pose_service.response))
51  return ErrorStatusError(msgs::ErrorStatus::ERR_UNKNOWN, "determineStartFeetPose", "Can't call 'FeetPoseGenerator'!");
52 
53  goal_feet = feet_pose_service.response.feet;
54 
55  return feet_pose_service.response.status;
56 }
57 
58 msgs::ErrorStatus transform(msgs::Foot& foot, ros::ServiceClient& transform_foot_pose_client, const std::string& target_frame)
59 {
60  msgs::TransformFootPoseService transform_service;
61  transform_service.request.foot = foot;
62  transform_service.request.target_frame.data = target_frame;
63 
64  if (!transform_foot_pose_client.call(transform_service.request, transform_service.response))
65  return ErrorStatusError(msgs::ErrorStatus::ERR_UNKNOWN, "transformToPlannerFrame", "Can't call 'FootPoseTransformer' for foot pose transform!");
66 
67  foot = transform_service.response.foot;
68 
69  return transform_service.response.status;
70 }
71 
72 msgs::ErrorStatus transform(msgs::Feet& feet, ros::ServiceClient& transform_feet_poses_client, const std::string& target_frame)
73 {
74  msgs::TransformFeetPosesService transform_service;
75  transform_service.request.feet = feet;
76  transform_service.request.target_frame.data = target_frame;
77 
78  if (!transform_feet_poses_client.call(transform_service.request, transform_service.response))
79  return ErrorStatusError(msgs::ErrorStatus::ERR_UNKNOWN, "transformToPlannerFrame", "Can't call 'FootPoseTransformer' for feet poses transform!");
80 
81  feet = transform_service.response.feet;
82 
83  return transform_service.response.status;
84 }
85 
86 msgs::ErrorStatus transform(msgs::StepPlan& step_plan, ros::ServiceClient& transform_step_plan_client, const std::string& target_frame)
87 {
88  msgs::TransformStepPlanService transform_service;
89  transform_service.request.step_plan = step_plan;
90  transform_service.request.target_frame.data = target_frame;
91 
92  if (!transform_step_plan_client.call(transform_service.request, transform_service.response))
93  return ErrorStatusError(msgs::ErrorStatus::ERR_UNKNOWN, "transformToPlannerFrame", "Can't call 'FootPoseTransformer' for step plan transform!");
94 
95  step_plan = transform_service.response.step_plan;
96 
97  return transform_service.response.status;
98 }
99 
100 
101 
102 bool getXYZ(ros::NodeHandle& nh, const std::string name, geometry_msgs::Vector3& val)
103 {
104  if (!nh.hasParam(name+"/x") || !nh.hasParam(name+"/y") || !nh.hasParam(name+"/z"))
105  {
106  ROS_ERROR("Couldn't retrieve parameter '%s' as Vector3", (nh.getNamespace()+"/"+name).c_str());
107  return false;
108  }
109 
110  nh.getParam(name+"/x", val.x);
111  nh.getParam(name+"/y", val.y);
112  nh.getParam(name+"/z", val.z);
113  return true;
114 }
115 
116 bool getRPY(ros::NodeHandle& nh, const std::string name, geometry_msgs::Vector3& val)
117 {
118  if (!nh.hasParam(name+"/roll") || !nh.hasParam(name+"/pitch") || !nh.hasParam(name+"/yaw"))
119  {
120  ROS_ERROR("Couldn't retrieve parameter '%s' as RPY orienation", (nh.getNamespace()+"/"+name).c_str());
121  return false;
122  }
123 
124  nh.getParam(name+"/roll", val.x);
125  nh.getParam(name+"/pitch", val.y);
126  nh.getParam(name+"/yaw", val.z);
127  return true;
128 }
129 
130 bool getFootSize(ros::NodeHandle& nh, geometry_msgs::Vector3& foot_size)
131 {
132  return getXYZ(nh, "foot/size", foot_size);
133 }
134 
135 bool getUpperBodySize(ros::NodeHandle& nh, geometry_msgs::Vector3& upper_body_size)
136 {
137  return getXYZ(nh, "upper_body/size", upper_body_size);
138 }
139 
140 bool getUpperBodyOriginShift(ros::NodeHandle& nh, geometry_msgs::Vector3& upper_body_origin_shift)
141 {
142  return getXYZ(nh, "upper_body/origin_shift", upper_body_origin_shift);
143 }
144 
145 
146 
147 bool getGridMapCoords(const nav_msgs::OccupancyGrid& map, double x, double y, int& map_x, int& map_y)
148 {
149  map_x = round((x-map.info.origin.position.x)/map.info.resolution);
150  map_y = round((y-map.info.origin.position.y)/map.info.resolution);
151 
152  if (map_x < 0 || (int) map.info.width <= map_x ||
153  map_y < 0 || (int) map.info.height <= map_y)
154  return false;
155 
156  return true;
157 }
158 
159 bool getGridMapIndex(const nav_msgs::OccupancyGrid& map, double x, double y, int& idx)
160 {
161  int map_x, map_y;
162 
163  if (!getGridMapCoords(map, x, y, map_x, map_y))
164  return false;
165  else
166  idx = map_x + map_y * map.info.width;
167 
168  return true;
169 }
170 }
bool getFootSize(ros::NodeHandle &nh, geometry_msgs::Vector3 &foot_size)
Definition: helper.cpp:130
bool getRPY(ros::NodeHandle &nh, const std::string name, geometry_msgs::Vector3 &val)
Definition: helper.cpp:116
bool getUpperBodyOriginShift(ros::NodeHandle &nh, geometry_msgs::Vector3 &upper_body_origin_shift)
Definition: helper.cpp:140
msgs::ErrorStatus determineStartFeetPose(msgs::Feet &start_feet, ros::ServiceClient &generate_feet_pose_client, const std_msgs::Header &header)
Definition: helper.cpp:5
bool call(MReq &req, MRes &res)
bool getGridMapCoords(const nav_msgs::OccupancyGrid &map, double x, double y, int &map_x, int &map_y)
Definition: helper.cpp:147
bool getGridMapIndex(const nav_msgs::OccupancyGrid &map, double x, double y, int &idx)
Definition: helper.cpp:159
bool getUpperBodySize(ros::NodeHandle &nh, geometry_msgs::Vector3 &upper_body_size)
Definition: helper.cpp:135
const std::string & getNamespace() const
static geometry_msgs::Quaternion createQuaternionMsgFromYaw(double yaw)
msgs::ErrorStatus determineGoalFeetPose(msgs::Feet &goal_feet, ros::ServiceClient &generate_feet_pose_client, const geometry_msgs::PoseStamped &goal_pose)
Definition: helper.cpp:43
bool getParam(const std::string &key, std::string &s) const
bool hasParam(const std::string &key) const
bool getXYZ(ros::NodeHandle &nh, const std::string name, geometry_msgs::Vector3 &val)
Definition: helper.cpp:102
#define ROS_ERROR(...)
msgs::ErrorStatus transform(msgs::Foot &foot, ros::ServiceClient &transform_foot_pose_client, const std::string &target_frame)
Definition: helper.cpp:58


vigir_footstep_planning_lib
Author(s): Alexander Stumpf
autogenerated on Mon Jun 10 2019 15:47:33