ros_plugin_demo
Demonstration of the ROS PlugInLib
 All Data Structures Namespaces Files Functions Variables Pages
Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes
plugin_demo_interface_namespace::PathPlanner Class Referenceabstract

Contain the Interface . More...

#include <path_planner.hpp>

Inheritance diagram for plugin_demo_interface_namespace::PathPlanner:
plugin_demo_plugins_namespace::Direct plugin_demo_plugins_namespace::DirectOrtho

Public Member Functions

void initialize (ros::NodeHandle roshandle)
 Initalize the global variables. More...
 
double getYawFromQuat (geometry_msgs::Quaternion quat)
 convert a quaternion into yaw More...
 
void tfFrameFromPoseStamped (geometry_msgs::PoseStamped *pose, tf::Transform *tf_tf)
 build a tf-frame for a given pose More...
 
int setPoints (geometry_msgs::Pose2D *start, geometry_msgs::Pose2D *target)
 replace the current start and target poses and call getPath() More...
 
int getPoints (geometry_msgs::Pose2D *start, geometry_msgs::Pose2D *target)
 returns the current start and target poses More...
 
virtual ~PathPlanner ()
 Intentionally left empty.
 

Protected Member Functions

 PathPlanner ()
 initialize init
 
virtual int onInit (ros::NodeHandle roshandle)
 In this function the plugIn can do some initialisation depending on a ROS NodeHandle. More...
 
virtual int getPath ()=0
 calculate current_path from start and target inside a plugIn. More...
 
void setPose2d (geometry_msgs::PoseStamped *pose3d, double x, double y, double theta)
 convert a given 2D-Pose into 3D-Stamped-Pose. More...
 

Protected Attributes

bool init
 true if initialized. More...
 
geometry_msgs::PoseStamped start
 starting pose of the path
 
geometry_msgs::PoseStamped target
 last pose of the path
 
nav_msgs::Path current_path
 contain the path
 

Private Member Functions

void getTargetCallback (const geometry_msgs::PoseStamped event)
 receives a new target pose and call getPath(). More...
 
void sendPathCallback (const ros::TimerEvent &event)
 call sendPath() More...
 
void getStarttCallback (const geometry_msgs::Pose2D event)
 receives a new start pose and call getPath(). More...
 
void sendPath ()
 publish current_path and the start_tf and target_tf frames
 

Private Attributes

ros::Subscriber getTargetSub
 listen for a new target pose
 
ros::Subscriber getStartSub
 listen for a new start pose
 
ros::Publisher pathPub
 send the path calculated by the plugIn
 
ros::Timer sendPathTimer
 periodic calling of the path publisher
 
tf::Transform start_tf
 the start tf-frame
 
tf::Transform target_tf
 the target tf-frame
 
tf::TransformBroadcaster tf_br
 send tf-transforms
 

Detailed Description

Contain the Interface .

Serve some mutual functions for all inherited plugIns.

Definition at line 23 of file path_planner.hpp.

Member Function Documentation

virtual int plugin_demo_interface_namespace::PathPlanner::getPath ( )
protectedpure virtual

calculate current_path from start and target inside a plugIn.

Returns
error code

Implemented in plugin_demo_plugins_namespace::Direct, and plugin_demo_plugins_namespace::DirectOrtho.

int plugin_demo_interface_namespace::PathPlanner::getPoints ( geometry_msgs::Pose2D *  start,
geometry_msgs::Pose2D *  target 
)

returns the current start and target poses

Parameters
startcurrent start pose
targetcurrent target pose
Returns
error code

Definition at line 76 of file path_planner.cpp.

77  {
78  start->x = this->start.pose.position.x;
79  start->y = this->start.pose.position.y;
80  start->theta = getYawFromQuat(this->start.pose.orientation);
81 
82  target->x = this->target.pose.position.x;
83  target->y = this->target.pose.position.y;
84  target->theta = getYawFromQuat(this->target.pose.orientation);
85 
86  return 0;
87  }
double getYawFromQuat(geometry_msgs::Quaternion quat)
convert a quaternion into yaw
geometry_msgs::PoseStamped target
last pose of the path
geometry_msgs::PoseStamped start
starting pose of the path
void plugin_demo_interface_namespace::PathPlanner::getStarttCallback ( const geometry_msgs::Pose2D  event)
private

receives a new start pose and call getPath().

Parameters
eventa pose message from the main part of this demo

Definition at line 107 of file path_planner.cpp.

108  {
109  setPose2d(&start, event.x, event.y, event.theta);
110 
112 
113  current_path.poses.clear();
114  getPath();
115 
116  sendPath();
117  }
void sendPath()
publish current_path and the start_tf and target_tf frames
void tfFrameFromPoseStamped(geometry_msgs::PoseStamped *pose, tf::Transform *tf_tf)
build a tf-frame for a given pose
tf::Transform start_tf
the start tf-frame
nav_msgs::Path current_path
contain the path
virtual int getPath()=0
calculate current_path from start and target inside a plugIn.
void setPose2d(geometry_msgs::PoseStamped *pose3d, double x, double y, double theta)
convert a given 2D-Pose into 3D-Stamped-Pose.
geometry_msgs::PoseStamped start
starting pose of the path
void plugin_demo_interface_namespace::PathPlanner::getTargetCallback ( const geometry_msgs::PoseStamped  event)
private

receives a new target pose and call getPath().

Parameters
eventa pose message from rViz

Definition at line 119 of file path_planner.cpp.

120  {
121  target = event;
122 
124 
125  current_path.poses.clear();
126  getPath();
127 
128  sendPath();
129  }
void sendPath()
publish current_path and the start_tf and target_tf frames
void tfFrameFromPoseStamped(geometry_msgs::PoseStamped *pose, tf::Transform *tf_tf)
build a tf-frame for a given pose
geometry_msgs::PoseStamped target
last pose of the path
nav_msgs::Path current_path
contain the path
tf::Transform target_tf
the target tf-frame
virtual int getPath()=0
calculate current_path from start and target inside a plugIn.
double plugin_demo_interface_namespace::PathPlanner::getYawFromQuat ( geometry_msgs::Quaternion  quat)

convert a quaternion into yaw

Parameters
quata Quaternion
Returns
the yaw angle of the quaternion

Definition at line 89 of file path_planner.cpp.

90  {
91  //geometry_msgs::Quaternion quat = ;
92  tf::Quaternion q(quat.x, quat.y, quat.z, quat.w);
93  tf::Matrix3x3 m(q);
94  double roll, pitch, yaw;
95  m.getRPY(roll, pitch, yaw);
96 
97  return yaw;
98  }
void plugin_demo_interface_namespace::PathPlanner::initialize ( ros::NodeHandle  roshandle)

Initalize the global variables.

Parameters
roshandlea valid ROS NodeHandle

Definition at line 14 of file path_planner.cpp.

15  {
16  if (init) {
17  ROS_WARN("[interface] plugin was already initialized. Nothing will be done.");
18  } else {
19  getTargetSub = roshandle.subscribe("set_target", 10, &PathPlanner::getTargetCallback, this);
20  getStartSub = roshandle.subscribe("set_start", 10, &PathPlanner::getStarttCallback, this);
21  pathPub = roshandle.advertise<nav_msgs::Path>("path", 10);
22  sendPathTimer = roshandle.createTimer(ros::Duration(2.0), &PathPlanner::sendPathCallback, this);
23 
24  setPose2d(&start, 0, 0, 0);
25  target = start;
26  target.header.stamp = ros::Time::now();
27 
30 
31  current_path.header.stamp = ros::Time::now();
32  current_path.header.frame_id = "world";
33  current_path.poses.push_back(start);
34  current_path.poses.push_back(target);
35 
36  onInit(roshandle);
37  init = true;
38 
39  sendPath();
40  }
41  }
ros::Timer sendPathTimer
periodic calling of the path publisher
void sendPathCallback(const ros::TimerEvent &event)
call sendPath()
void getTargetCallback(const geometry_msgs::PoseStamped event)
receives a new target pose and call getPath().
ros::Publisher pathPub
send the path calculated by the plugIn
void getStarttCallback(const geometry_msgs::Pose2D event)
receives a new start pose and call getPath().
virtual int onInit(ros::NodeHandle roshandle)
In this function the plugIn can do some initialisation depending on a ROS NodeHandle.
void sendPath()
publish current_path and the start_tf and target_tf frames
void tfFrameFromPoseStamped(geometry_msgs::PoseStamped *pose, tf::Transform *tf_tf)
build a tf-frame for a given pose
ros::Subscriber getStartSub
listen for a new start pose
tf::Transform start_tf
the start tf-frame
geometry_msgs::PoseStamped target
last pose of the path
ros::Subscriber getTargetSub
listen for a new target pose
nav_msgs::Path current_path
contain the path
tf::Transform target_tf
the target tf-frame
void setPose2d(geometry_msgs::PoseStamped *pose3d, double x, double y, double theta)
convert a given 2D-Pose into 3D-Stamped-Pose.
geometry_msgs::PoseStamped start
starting pose of the path
int plugin_demo_interface_namespace::PathPlanner::onInit ( ros::NodeHandle  roshandle)
protectedvirtual

In this function the plugIn can do some initialisation depending on a ROS NodeHandle.

Parameters
roshandlea valid ROS NodeHandle
Returns
error code

Reimplemented in plugin_demo_plugins_namespace::Direct, and plugin_demo_plugins_namespace::DirectOrtho.

Definition at line 43 of file path_planner.cpp.

44  {
45  ROS_INFO("[interface] plugIn has no onInit function");
46  }
void plugin_demo_interface_namespace::PathPlanner::sendPathCallback ( const ros::TimerEvent &  event)
private

call sendPath()

Parameters
eventsome time values

Definition at line 131 of file path_planner.cpp.

132  {
133  sendPath();
134  }
void sendPath()
publish current_path and the start_tf and target_tf frames
int plugin_demo_interface_namespace::PathPlanner::setPoints ( geometry_msgs::Pose2D *  start,
geometry_msgs::Pose2D *  target 
)

replace the current start and target poses and call getPath()

Parameters
startnew start pose
targetnew target pose
Returns
error code

Definition at line 60 of file path_planner.cpp.

61  {
62  setPose2d( &(this->start), start->x, start->y, start->theta);
63  setPose2d( &(this->target), target->x, target->y, target->theta);
64 
67 
68  current_path.poses.clear();
69  getPath();
70 
71  sendPath();
72 
73  return 0;
74  }
void sendPath()
publish current_path and the start_tf and target_tf frames
void tfFrameFromPoseStamped(geometry_msgs::PoseStamped *pose, tf::Transform *tf_tf)
build a tf-frame for a given pose
tf::Transform start_tf
the start tf-frame
geometry_msgs::PoseStamped target
last pose of the path
nav_msgs::Path current_path
contain the path
tf::Transform target_tf
the target tf-frame
virtual int getPath()=0
calculate current_path from start and target inside a plugIn.
void setPose2d(geometry_msgs::PoseStamped *pose3d, double x, double y, double theta)
convert a given 2D-Pose into 3D-Stamped-Pose.
geometry_msgs::PoseStamped start
starting pose of the path
void plugin_demo_interface_namespace::PathPlanner::setPose2d ( geometry_msgs::PoseStamped *  pose3d,
double  x,
double  y,
double  theta 
)
protected

convert a given 2D-Pose into 3D-Stamped-Pose.

Parameters
pose3dpointer to the target variable
xthe x-value of the 2D-Pose
ythe y-value of the 2D-Pose
thetathe theta-value of the 2D-Pose

Definition at line 48 of file path_planner.cpp.

49  {
50  pose3d->header.stamp = ros::Time::now();
51  pose3d->pose.position.x = x;
52  pose3d->pose.position.y = y;
53  pose3d->pose.position.z = 0;
54  pose3d->pose.orientation.x = 0;
55  pose3d->pose.orientation.y = 0;
56  pose3d->pose.orientation.z = sin(theta * 0.5);
57  pose3d->pose.orientation.w = cos(theta * 0.5);
58  }
void plugin_demo_interface_namespace::PathPlanner::tfFrameFromPoseStamped ( geometry_msgs::PoseStamped *  pose,
tf::Transform *  tf_tf 
)

build a tf-frame for a given pose

Parameters
posethe pose for the tf-frame
tf_tfthe resulting tf-frame

Definition at line 100 of file path_planner.cpp.

101  {
102  tf_tf->setOrigin( tf::Vector3(pose->pose.position.x, pose->pose.position.y, pose->pose.position.z) );
103  tf::Quaternion q(pose->pose.orientation.x, pose->pose.orientation.y, pose->pose.orientation.z, pose->pose.orientation.w);
104  tf_tf->setRotation(q);
105  }

Field Documentation

bool plugin_demo_interface_namespace::PathPlanner::init
protected

true if initialized.

Definition at line 54 of file path_planner.hpp.


The documentation for this class was generated from the following files: