dc_motor.h

Go to the documentation of this file.
00001 
00040 #ifndef DRV_DC_MOTOR_H
00041 #define DRV_DC_MOTOR_H
00042 
00043 #include "hw_dc_motor.h"
00044 
00045 #include <algo/pid_control.h>
00046 
00047 #include <drv/pwm.h>
00048 #include <drv/timer.h>
00049 #include <drv/adc.h>
00050 
00051 #include <cfg/macros.h>
00052 
00053 #include "appconfig.h"
00054 
00058 #define DC_MOTOR_ACTIVE     BV(0)     
00059 #define DC_MOTOR_DIR        BV(1)     
00060 
00061 
00064 typedef uint16_t dc_speed_t;
00065 
00069 typedef struct DCMotorConfig
00070 {
00071     PidCfg pid_cfg;         
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     mtime_t sample_delay;   
00080 
00081     bool dir;               
00082 
00083 } DCMotorConfig;
00084 
00085 
00089 typedef struct DCMotor
00090 {
00091     const DCMotorConfig *cfg; 
00092     PidContext pid_ctx;       
00093 
00094     int index;                
00095     uint32_t status;          
00096     dc_speed_t tgt_speed;     
00097 
00098 } DCMotor;
00099 
00100 void dc_motor_setDir(int index, bool dir);
00101 void dc_motor_enable(int index, bool state);
00102 void dc_motor_setSpeed(int index, dc_speed_t speed);
00103 void dc_motor_setup(int index, DCMotorConfig *cfg);
00104 void dc_motor_init(void);
00105 
00106 #endif /* DRV_DC_MOTOR_H */