Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef _DEVTHROTTLE_H_
00012 #define _DEVTHROTTLE_H_
00013
00014 #include <stdio.h>
00015 #include <stdint.h>
00016 #include <math.h>
00017
00018 #include <ros/ros.h>
00019
00020 #include "../servo.h"
00021 #include "avr_controller.h"
00022
00023 #define DBG(format,args...) ROS_DEBUG(format, ## args)
00024
00025
00026 class devthrottle: Servo
00027 {
00028 public:
00029
00030
00031
00032
00033 double rpm_redline;
00034 double throttle_limit;
00035 int avr_kp;
00036 int avr_ki;
00037 int avr_kd;
00038 int avr_out_max;
00039
00040
00041
00042
00043 double avr_pos_max;
00044 int avr_pos_min;
00045 double avr_pos_range;
00046 int avr_pos_epsilon;
00047
00048 devthrottle(bool train);
00049 ~devthrottle() {};
00050
00051 int Open(const char *device);
00052 int Close(void);
00053
00054 int64_t GetTime();
00055
00056
00057 float get_position(void) {return cur_position;}
00058
00059
00060 bool query_estop(void);
00061 int query_pid(float *pwm, float *dstate, float *istate);
00062 int query_rpms(float *data);
00063 int query_status();
00064
00065
00066 int throttle_absolute(float position);
00067 int throttle_relative(float delta);
00068
00069 private:
00070
00071 bool training;
00072 bool already_configured;
00073
00074 struct avr_cmd stat;
00075 struct avr_cmd cmd;
00076 struct avr_cmd resp;
00077
00078
00079 uint8_t *cmd_p;
00080 uint8_t *resp_p;
00081
00082 float cur_position;
00083 float last_req;
00084
00085 int calibrate_idle(void);
00086 uint8_t cmd_compute_csum(uint8_t *buffer, int len);
00087 int configure_controller(void);
00088 void decode_char(char c, int *resp_bytes, int *resp_digits);
00089 int format_cmd(char *cmdstr);
00090 int read_byte(int linelen);
00091 int send_cmd(int ccode);
00092 int send_cmd08(int ccode, uint8_t data);
00093 int send_cmd16(int ccode, uint16_t data);
00094 int send_cmd32(int ccode, uint32_t data);
00095 int send_goto(uint8_t pos);
00096 int servo_cmd(void);
00097 int validate_response(int resp_bytes, int linelen);
00098
00099
00100 inline float limit_travel(float position)
00101 {
00102 if (position > throttle_limit) position = throttle_limit;
00103 else if (position < 0.0) position = 0.0;
00104 return position;
00105 }
00106
00107
00108 inline uint8_t pos2avr(float position)
00109 {return (int) rintf(avr_pos_min + position * avr_pos_range);}
00110
00111 inline float avr2pos(uint8_t avr_val)
00112 {return (avr_val - avr_pos_min) / avr_pos_range;}
00113 };
00114
00115 #endif // _DEVTHROTTLE_H_