app-BeoPilot.cpp
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 #include "ros/ros.h"
00028 #include "std_msgs/String.h"
00029 #include "BeoPilot.H"
00030 #include <geometry_msgs/Twist.h>
00031 #include <tf/transform_broadcaster.h>
00032 #include <nav_msgs/Odometry.h>
00033 #include <sstream>
00034
00035
00036
00037 BeoPilot * beopilot;
00038 void cmd_vel_Callback(geometry_msgs::Twist msg)
00039 {
00040 float trans = msg.linear.x;
00041 float rots = msg.angular.z;
00042 ROS_INFO("cmd_vel_callback: %f, %f", trans, rots);
00043 beopilot->SetMotorsPid(rots,trans);
00044 }
00045
00046 int main(int argc, char **argv)
00047 {
00048 ros::init(argc, argv, "beopilot");
00049 ros::NodeHandle n;
00050 ros::NodeHandle n_priv("~");
00051 ros::Publisher odom_pub = n.advertise<nav_msgs::Odometry>("/beobot2/odom", 1);
00052 tf::TransformBroadcaster odom_broadcaster;
00053 beopilot = new BeoPilot();
00054 beopilot->start();
00055 ros::Subscriber motor_sub = n.subscribe("/beobot2/cmd_vel",1,cmd_vel_Callback);
00056
00057 ros::Rate pub_rate(10);
00058 double x = 0.0f;
00059 double y = 0.0f;
00060 double th = 0.0f;
00061
00062 double vx = 0.0f;
00063 double vy = 0.0f;
00064 double vth = 0.0f;
00065
00066 ros::Time current_time, last_time;
00067 current_time = ros::Time::now();
00068 last_time = ros::Time::now();
00069
00070 beopilot->resetEncoder();
00071 ROS_INFO("x %f y %f th %f vx %f vy %f vth %f", beopilot->itsPosition.x, beopilot->itsPosition.y, beopilot->itsPosition.z, beopilot->itsVelocity.x, beopilot->itsVelocity.y, beopilot->itsVelocity.z);
00072
00073 while (ros::ok())
00074 {
00075 beopilot->UpdateRCStatus();
00076 x = -beopilot->itsPosition.x;
00077 y = beopilot->itsPosition.y;
00078 th = -beopilot->itsPosition.z;
00079
00080 vx = -beopilot->itsVelocity.x;
00081 vy = beopilot->itsVelocity.y;
00082 vth = -beopilot->itsVelocity.z;
00083
00084 ROS_INFO("x %f y %f th %f vx %f vy %f vth %f", x, y, th, vx, vy, vth);
00085
00086
00087
00088 current_time = ros::Time::now();
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101 geometry_msgs::Quaternion odom_quat = tf::createQuaternionMsgFromYaw(th);
00102
00103
00104 geometry_msgs::TransformStamped odom_trans;
00105 odom_trans.header.stamp = current_time;
00106 odom_trans.header.frame_id = "/beobot2/odom";
00107 odom_trans.child_frame_id = "/beobot2/base_link";
00108
00109 odom_trans.transform.translation.x = x;
00110 odom_trans.transform.translation.y = y;
00111 odom_trans.transform.translation.z = 0.0f;
00112 odom_trans.transform.rotation = odom_quat;
00113
00114
00115 odom_broadcaster.sendTransform(odom_trans);
00116
00117
00118 nav_msgs::Odometry odom;
00119 odom.header.stamp = current_time;
00120 odom.header.frame_id = "odom";
00121
00122
00123 odom.pose.pose.position.x = x;
00124 odom.pose.pose.position.y = y;
00125 odom.pose.pose.position.z = 0.0f;
00126 odom.pose.pose.orientation = odom_quat;
00127
00128
00129 odom.child_frame_id = "base_link";
00130 odom.twist.twist.linear.x = vx;
00131 odom.twist.twist.linear.y = vy;
00132 odom.twist.twist.angular.z = vth;
00133
00134
00135 odom_pub.publish(odom);
00136
00137 last_time = current_time;
00138 ros::spinOnce();
00139 pub_rate.sleep();
00140 }
00141
00142
00143 return 0;
00144 }
00145
00146
00147
00148
00149