dc_motor.h

Go to the documentation of this file.
00001 
00043 #ifndef DRV_DC_MOTOR_H
00044 #define DRV_DC_MOTOR_H
00045 
00046 #include "hw/hw_dc_motor.h"
00047 
00048 #include "cfg/cfg_dc_motor.h"
00049 #include <cfg/macros.h>
00050 
00051 #include <algo/pid_control.h>
00052 
00053 #include <drv/pwm.h>
00054 #include <drv/timer.h>
00055 #include <drv/adc.h>
00056 
00057 #define DC_MOTOR_NO_EXPIRE        -1  ///< The DC motor runs do not expire, so it runs forever.
00058 #define DC_MOTOR_NO_DEV_SPEED     -1  ///< Disable the speed acquire from device (like trimmer, etc.).
00059 
00063 typedef uint16_t dc_speed_t;
00064 
00068 typedef struct DCMotorConfig
00069 {
00070     PidCfg pid_cfg;         
00071     bool pid_enable;        
00072 
00073     PwmDev pwm_dev;         
00074     pwm_freq_t freq;        
00075 
00076     adc_ch_t adc_ch;        
00077     adcread_t adc_max;      
00078     adcread_t adc_min;      
00079 
00080     bool dir;               
00081     bool braked;            
00082 
00083     dc_speed_t speed;       
00084 
00085     int speed_dev_id;       
00086 
00087 } DCMotorConfig;
00088 
00089 
00093 typedef struct DCMotor
00094 {
00095     const DCMotorConfig *cfg; 
00096     PidContext pid_ctx;       
00097 
00098     int index;                
00099     uint32_t status;          
00100     dc_speed_t tgt_speed;     
00101 
00102     ticks_t expire_time;      
00103 
00104 } DCMotor;
00105 
00106 void dc_motor_setDir(int index, bool dir);
00107 void dc_motor_enable(int index, bool state);
00108 void dc_motor_setSpeed(int index, dc_speed_t speed);
00109 void dc_motor_startTimer(int index, mtime_t on_time);
00110 void dc_motor_waitStop(int index);
00111 void dc_motor_setup(int index, DCMotorConfig *dcm_conf);
00112 dc_speed_t dc_motor_readTargetSpeed(int index);
00113 void dc_motor_setPriority(int priority);
00114 void dc_motor_init(void);
00115 
00116 
00122 int dc_motor_testSetUp(void);
00123 void dc_motor_testRun(void);
00124 int dc_motor_testTearDown(void);
00125 
00126 #endif /* DRV_DC_MOTOR_H */