SMACC
Loading...
Searching...
No Matches
path_tools.cpp
Go to the documentation of this file.
1/*****************************************************************************************************************
2 * ReelRobotix Inc. - Software License Agreement Copyright (c) 2018
3 * Authors: Pablo Inigo Blasco, Brett Aldrich
4 *
5 ******************************************************************************************************************/
6#include <ros/ros.h>
7#include <geometry_msgs/PoseStamped.h>
8#include <tf/transform_datatypes.h>
9#include <angles/angles.h>
10
11namespace cl_move_base_z
12{
13 geometry_msgs::PoseStamped makePureSpinningSubPlan(const geometry_msgs::PoseStamped& start, double dstRads, std::vector<geometry_msgs::PoseStamped>& plan, double puresSpinningRadStep=1000)
14 {
15 double startYaw = tf::getYaw(start.pose.orientation);
16 //ROS_INFO("pure spining start yaw: %lf", startYaw);
17 //ROS_INFO("pure spining goal yaw: %lf", dstRads);
18 //ROS_WARN_STREAM("pure spinning start pose: " << start);
19
20 double goalAngleOffset = angles::shortest_angular_distance(startYaw, dstRads);
21 //ROS_INFO("shortest angle: %lf", goalAngleOffset);
22
23 double radstep = 0.005;
24
25 if( goalAngleOffset>=0)
26 {
27 // angle positive turn counterclockwise
28 //ROS_INFO("pure spining counterclockwise");
29 for(double dangle = 0; dangle <= goalAngleOffset;dangle+=radstep )
30 {
31 geometry_msgs::PoseStamped p= start;
32 double yaw = startYaw+ dangle;
33 //ROS_INFO("pure spining counterclockwise, current path yaw: %lf, dangle: %lf, angleoffset %lf, radstep %lf pathsize(%ld)", yaw, dangle, goalAngleOffset, radstep, plan.size());
34 p.pose.orientation = tf::createQuaternionMsgFromYaw(yaw);
35 plan.push_back(p);
36 }
37 }
38 else
39 {
40 // angle positive turn clockwise
41 //ROS_INFO("pure spining clockwise");
42 for(double dangle = 0; dangle >= goalAngleOffset;dangle-=radstep )
43 {
44 //ROS_INFO("dangle: %lf", dangle);
45 geometry_msgs::PoseStamped p= start;
46 double yaw = startYaw+ dangle;
47 //ROS_INFO("pure spining clockwise, yaw: %lf, dangle: %lf, angleoffset %lf radstep %lf", yaw, dangle, goalAngleOffset,radstep);
48 p.pose.orientation = tf::createQuaternionMsgFromYaw(yaw);
49 plan.push_back(p);
50 }
51 }
52
53 //ROS_INFO("pure spining end yaw: %lf", dstRads);
54 geometry_msgs::PoseStamped end= start;
55 end.pose.orientation = tf::createQuaternionMsgFromYaw(dstRads);
56 plan.push_back(end);
57
58 return end;
59 }
60
61 geometry_msgs::PoseStamped makePureStraightSubPlan(const geometry_msgs::PoseStamped& startOrientedPose,
62 const geometry_msgs::Point& goal,
63 double length,
64 std::vector<geometry_msgs::PoseStamped>& plan)
65 {
66 double dx = 0.01; // 1 cm
67 double steps = length /dx;
68 double dt = 1.0/steps;
69
70 // geometry_msgs::PoseStamped end;
71 // end.pose.orientation = startOrientedPose.pose.orientation;
72 //end.pose.position = goal;
73 plan.push_back(startOrientedPose);
74
75 //ROS_INFO_STREAM("Pure straight, start: " << startOrientedPose << std::endl << "end: " << goal);
76 for(double t=0; t <=1.0; t+=dt)
77 {
78 geometry_msgs::PoseStamped p = startOrientedPose;
79
80 p.pose.position.x = startOrientedPose.pose.position.x *(1 - t) + goal.x * t;
81 p.pose.position.y = startOrientedPose.pose.position.y *(1 - t) + goal.y * t;
82 p.pose.orientation = startOrientedPose.pose.orientation;
83
84 plan.push_back(p);
85 }
86
87 return plan.back();
88 }
89}
geometry_msgs::PoseStamped makePureStraightSubPlan(const geometry_msgs::PoseStamped &startOrientedPose, const geometry_msgs::Point &goal, double length, std::vector< geometry_msgs::PoseStamped > &plan)
Definition: path_tools.cpp:61
geometry_msgs::PoseStamped makePureSpinningSubPlan(const geometry_msgs::PoseStamped &start, double dstRads, std::vector< geometry_msgs::PoseStamped > &plan, double puresSpinningRadStep=1000)
Definition: path_tools.cpp:13