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 #include <ros/ros.h>
00031 #include <tf/transform_listener.h>
00032 #include <std_msgs/Float64.h>
00033 #include <string>
00034 #include "hector_roll_pitch_stabilizer/DoScan.h"
00035
00036 std::string p_base_frame_;
00037 std::string p_base_stabilized_frame_;
00038
00039
00040 tf::TransformListener* tfL_;
00041 tf::StampedTransform transform_;
00042
00043 ros::Publisher pub_desired_roll_angle_;
00044 ros::Publisher pub_desired_pitch_angle_;
00045 ros::ServiceServer scan_server_;
00046
00047 bool updatesEnabled = true;
00048
00049 void stabilize() {
00050 try
00051 {
00052 tfL_->lookupTransform(p_base_frame_, p_base_stabilized_frame_, ros::Time(0), transform_);
00053
00054 tfScalar yaw, pitch, roll;
00055 transform_.getBasis().getEulerYPR(yaw, pitch, roll);
00056
00057 std_msgs::Float64 tmp;
00058
00059 tmp.data = -roll;
00060 pub_desired_roll_angle_.publish(tmp);
00061
00062 tmp.data = -pitch;
00063 pub_desired_pitch_angle_.publish(tmp);
00064 }
00065 catch(tf::TransformException e)
00066 {
00067
00068
00069 }
00070 }
00071
00072 void updateTimerCallback(const ros::TimerEvent& event)
00073 {
00074 if ( updatesEnabled ) {
00075 stabilize();
00076 }
00077 }
00078
00079 bool doScan(hector_roll_pitch_stabilizer::DoScan::Request &request, hector_roll_pitch_stabilizer::DoScan::Response &response) {
00080 updatesEnabled = false;
00081
00082 std_msgs::Float64 tmp;
00083
00084
00085
00086 stabilize();
00087
00088
00089 for ( double pos = 0; pos > request.min_angle_pitch; pos -= request.step ) {
00090 tmp.data = pos;
00091 pub_desired_pitch_angle_.publish(tmp);
00092 usleep(1000*request.sleep_time_ms);
00093 }
00094
00095 for ( double pos = request.min_angle_pitch; pos <= request.max_angle_pitch; pos += request.step ) {
00096 tmp.data = pos;
00097 pub_desired_pitch_angle_.publish(tmp);
00098 usleep(1000*request.sleep_time_ms);
00099 }
00100
00101 for ( double pos = request.max_angle_pitch; pos >= 0.0; pos -= request.step ) {
00102 tmp.data = pos;
00103 pub_desired_pitch_angle_.publish(tmp);
00104 usleep(1000*request.sleep_time_ms);
00105 }
00106
00107
00108 for ( double pos = 0; pos > request.min_angle_roll; pos -= request.step ) {
00109 tmp.data = pos;
00110 pub_desired_pitch_angle_.publish(tmp);
00111 usleep(1000*request.sleep_time_ms);
00112 }
00113
00114 for ( double pos = request.min_angle_roll; pos <= request.max_angle_roll; pos += request.step ) {
00115 tmp.data = pos;
00116 pub_desired_roll_angle_.publish(tmp);
00117 usleep(1000*request.sleep_time_ms);
00118 }
00119
00120 for ( double pos = request.max_angle_roll; pos >= 0.0; pos -= request.step ) {
00121 tmp.data = pos;
00122 pub_desired_pitch_angle_.publish(tmp);
00123 usleep(1000*request.sleep_time_ms);
00124 }
00125
00126 updatesEnabled = true;
00127
00128 return true;
00129 }
00130
00131 int main(int argc, char **argv) {
00132 ros::init(argc, argv, ROS_PACKAGE_NAME);
00133 ros::NodeHandle n;
00134 ros::NodeHandle pn("~");
00135
00136 pn.param("base_frame", p_base_frame_, std::string("base_frame"));
00137 pn.param("base_stabilized_frame", p_base_stabilized_frame_, std::string("base_stabilized_frame"));
00138
00139 tfL_ = new tf::TransformListener();
00140
00141 ros::Timer update_timer = pn.createTimer(ros::Duration(1.0 / 30), &updateTimerCallback, false);
00142
00143 pub_desired_roll_angle_ = pn.advertise<std_msgs::Float64>("/desired_roll_angle",10,false);
00144 pub_desired_pitch_angle_ = pn.advertise<std_msgs::Float64>("/desired_pitch_angle",10,false);
00145
00146 scan_server_ = n.advertiseService(std::string("/hector_roll_pitch_stabilizer/do_scan"), &doScan);
00147
00148 ros::spin();
00149
00150 delete tfL_;
00151
00152 return 0;
00153 }
00154