base_motor_driver.h
Go to the documentation of this file.
00001 #ifndef __BASE_MOTOR_DRIVER_H__
00002 #define __BASE_MOTOR_DRIVER_H__
00003 
00034 #include <fcntl.h>      // open modes devices
00035 #include <cmath>
00036 #include <cstring>
00037 #include <sys/sem.h>    // IPC semaphores
00038 #include <termios.h>    // struct termios
00039 #include <ros/ros.h>
00040 #include "maggie_data.h"
00041 
00042 // device names
00043 //TODO: convert this to rosparam
00044 #define DEVICE_NAME1    "/dev/motor_base2"
00045 #define DEVICE_NAME2    "/dev/motor_base1"
00046 
00047 // semaphore name
00048 #define SEM_FILENAME    "/tmp/sem"
00049 key_t SEMFDID;
00050 
00051 // baud rate
00052 #define BAUDRATE        B19200
00053 
00054 // period between samples in seconds
00055 #define PERIOD          0.060
00056 
00057 // length for GST command response
00058 #define SIZE_REPORT_GST 8
00059 
00060 typedef struct {
00061         double v;       // linear velocity (mm / sec)
00062         double w;       // angular velocity (degrees / sec)
00063         double x;       // x position (mm)
00064         double y;       // y position (mm)
00065         double theta;   // angle (degrees)
00066 } cinematic_data;
00067 
00068 class BaseMotor {
00069     public:
00073         BaseMotor();
00074 
00078         ~BaseMotor();
00079 
00087         int init_communication();
00088 
00093         int end_communication();
00094 
00103         int enable_motors();
00104 
00113         int disable_motors();
00114 
00125         int enable_disable_motor(int *fd, const char *order);
00126 
00132         int read_data(cinematic_data *data);
00133 
00141         int read_data_variable_time_diff(cinematic_data *data, double time_since_last_call);
00142 
00149         int set_velocity(double v, double w);
00150 
00158         int set_displacement_velocity(double d, double v, double w);
00159 
00165         int move_ahead(double distance);
00166 
00172         int relative_turn(double theta);
00173 
00178         int reset_odometry();
00179 
00185         int update_odometry(double x, double y, double theta);
00186 
00192         cinematic_data * get_estimate_position();
00193 
00201         int set_estimate_position(double x, double y, double theta);
00202 
00203         std::string motor_order;
00204 
00205     private:
00206         // file descriptors
00207         int _fd_motor1, _fd_motor2;
00208 
00209         // motors odometry
00210         double _distance1, _distance2, _before_distance1, _before_distance2;
00211         cinematic_data _current_cinematic, _last_cinematic;
00212 
00213         // aggregated variable for estimated position
00214         int _corrected_data;
00215         cinematic_data _current_estimated, _before_estimated;
00216 };
00217 
00218 #endif


maggie_base
Author(s): Raul Perula-Martinez
autogenerated on Thu Apr 23 2015 22:19:14