00001 00020 #ifndef __ROBOT_STATE__ 00021 #define __ROBOT_STATE__ 00022 00023 #include <boost/thread/mutex.hpp> 00024 #include "ros/ros.h" 00025 #include "nav_msgs/Odometry.h" 00026 #include <tf/transform_broadcaster.h> 00031 class RobotState 00032 { 00033 00034 protected: 00035 tf::TransformBroadcaster odom_broadcaster; 00036 00037 //Position at x-axis 00038 double x; 00039 //Position at y-axis 00040 double y; 00041 //Alignment in radien 00042 double th; 00043 //Velocity x-axis [m/s] 00044 double vx; 00045 //Velocity y-axis [m/s] 00046 double vy; 00047 //Velocity z-axis [rad] 00048 double vth; 00049 boost::mutex mutex; 00050 //Connection with can-bus 00051 int socket; 00052 00053 public: 00054 ros::Publisher odom_pub; 00055 ros::NodeHandle* n; 00056 RobotState(ros::NodeHandle* n, int socket) : socket(socket), n(n) 00057 { 00058 odom_pub = n->advertise<nav_msgs::Odometry>("odom", 50); 00059 x = 0.0; 00060 y = 0.0; 00061 th = 0.0; 00062 vx = 0.0; 00063 vy = 0.0; 00064 vth = 0.0; 00065 }; 00066 00067 void sendTransformOdomTF(geometry_msgs::TransformStamped odom_trans) { odom_broadcaster.sendTransform(odom_trans); } 00068 00069 void publishOdomMsg(nav_msgs::Odometry odom) { odom_pub.publish(odom); } 00070 00071 ros::NodeHandle* getNodeHandle() {return n;} 00072 00073 double getX() 00074 { 00075 boost::mutex::scoped_lock scoped_lock(mutex); 00076 return x; 00077 }; 00078 00079 double getY() 00080 { 00081 boost::mutex::scoped_lock scoped_lock(mutex); 00082 return y; 00083 }; 00084 00085 double getTh() 00086 { 00087 boost::mutex::scoped_lock scoped_lock(mutex); 00088 return th; 00089 }; 00090 00091 double getVX() 00092 { 00093 boost::mutex::scoped_lock scoped_lock(mutex); 00094 return vx; 00095 }; 00096 00097 double getVY() 00098 { 00099 boost::mutex::scoped_lock scoped_lock(mutex); 00100 return vy; 00101 }; 00102 00103 double getVTh() 00104 { 00105 boost::mutex::scoped_lock scoped_lock(mutex); 00106 return vth; 00107 }; 00108 00109 int getSocket() 00110 { 00111 return socket; 00112 } 00113 00114 void setX(double x) 00115 { 00116 boost::mutex::scoped_lock scoped_lock(mutex); 00117 this->x = x; 00118 }; 00119 00120 void setY(double y) 00121 { 00122 boost::mutex::scoped_lock scoped_lock(mutex); 00123 this->y = y; 00124 }; 00125 00126 void setTh(double th) 00127 { 00128 boost::mutex::scoped_lock scoped_lock(mutex); 00129 this->th = th; 00130 }; 00131 00132 void setVX(double vx) 00133 { 00134 boost::mutex::scoped_lock scoped_lock(mutex); 00135 this->vx = vx; 00136 }; 00137 00138 void setVY(double vy) 00139 { 00140 boost::mutex::scoped_lock scoped_lock(mutex); 00141 this->vy = vy; 00142 }; 00143 00144 void setVTh(double vth) 00145 { 00146 boost::mutex::scoped_lock scoped_lock(mutex); 00147 this->vth = vth; 00148 }; 00149 00150 }; 00151 00152 #endif 00153