ThirdRobotInterface.h
Go to the documentation of this file.
00001 #ifndef THIRD_ROBOT_INTERFACE_H_
00002 #define THIRD_ROBOT_INTERFACE_H_
00003 
00004 // For ROS
00005 #include "ros/ros.h"
00006 #include "geometry_msgs/Twist.h"                // cmd_vel
00007 
00008 // iMCs01
00009 #include "imcs01_driver/driver/urbtc.h"
00010 #include "imcs01_driver/driver/urobotc.h"
00011 
00012 // For std
00013 #include <string>
00014 #include <mutex>
00015 
00016 // For old c
00017 #include <termios.h>
00018 
00019 enum
00020 {
00021   FRONT,
00022   REAR
00023 };
00024 
00025 enum
00026 {
00027   ROBOT_STASIS_FORWARD,
00028   ROBOT_STASIS_FORWARD_STOP,
00029   ROBOT_STASIS_BACK,
00030   ROBOT_STASIS_BACK_STOP,
00031   ROBOT_STASIS_OTHERWISE
00032 };
00033 
00034 enum
00035 {
00036   FORWARD_MODE,
00037   FORWARD_STOP_MODE,
00038   BACK_MODE,
00039   BACK_STOP_MODE,
00040   STOP_MODE
00041 };
00042 
00043 
00044 template<typename N, typename M>
00045 inline double MIN(const N& a, const M& b)
00046 {
00047   return a < b ? a : b;
00048 }
00049 
00050 template<typename N, typename M>
00051 inline double MAX(const N& a, const M& b)
00052 {
00053   return a > b ? a : b;
00054 }
00055 
00056 template<typename T>
00057 inline double NORMALIZE(const T& z)
00058 {
00059   return atan2(sin(z), cos(z));
00060 }
00061 
00062 int plus_or_minus(double value);
00063 
00064 namespace cirkit
00065 {
00066 
00067 class ThirdRobotInterface
00068 {
00069 public:
00071   ThirdRobotInterface(const std::string& new_serial_port_imcs01, int new_baudrate_imcs01);
00073   ~ThirdRobotInterface();
00075   virtual int openSerialPort();
00077   virtual int setSerialPort();
00079   virtual int closeSerialPort();
00081   virtual void setParams(double pulse_rate, double geer_rate, double wheel_diameter_right, double wheel_diameter_left, double tred_width);
00083   virtual geometry_msgs::Twist drive(double linear_speed, double angular_speed);
00085   virtual geometry_msgs::Twist driveDirect(double front_angular, double rear_speed);// front_angular in [deg]
00087   virtual int getEncoderPacket();
00089   virtual void calculateOdometry();
00091   virtual void resetOdometry();
00093   virtual void setOdometry(double new_x, double new_y, double new_yaw);
00095   virtual void writeCmd(ccmd cmd);
00096 
00098   double odometry_x_;
00100   double odometry_y_;
00102   double odometry_yaw_;
00104   double steer_angle;
00106   int stasis_;
00107 
00108 protected:
00110 
00116   int parseEncoderPackets();
00117   int parseFrontEncoderCounts();
00118   int parseRearEncoderCounts();
00119   geometry_msgs::Twist fixFrontAngle(double angular_diff);
00120 
00122   struct uin cmd_uin;
00123   //struct uout cmd_uout;
00124   struct ccmd cmd_ccmd;
00126   std::string imcs01_port_name;
00128   int fd_imcs01;
00130   int baudrate_imcs01;
00132   termios oldtio_imcs01;
00133   termios newtio_imcs01;
00136   int delta_rear_encoder_counts[2] {0, 0};
00139   int last_rear_encoder_counts[2] {0, 0};
00141   double last_rear_encoder_time;
00143   double delta_rear_encoder_time;
00146   double delta_dist[2] {0, 0};
00147   double last_delta_dist[2] {0, 0};
00149   double last_odometry_yaw = 0.0;
00151   double PulseRate = 40.0;
00153   double GeerRate = 33.0;
00155   double WheelDiameter[2] {0.2705, 0.275};
00157   double TredWidth = 0.595;
00159   double linear_velocity;
00161   int runmode;
00163   std::mutex communication_mutex_;
00164 };
00165 }
00166 #endif // THIRD_ROBOT_INTERFACE_H_


cirkit_unit03_driver
Author(s): CIR-KIT
autogenerated on Thu Jun 6 2019 21:08:20