Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F79191342
motorcontrol.h
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sun, Aug 25, 05:08
Size
3 KB
Mime Type
text/x-c
Expires
Tue, Aug 27, 05:08 (2 d)
Engine
blob
Format
Raw Data
Handle
20146650
Attached To
R6619 Oncilla Motordriver Firmware
motorcontrol.h
View Options
#ifndef __MOTORCONTROL_H__
#define __MOTORCONTROL_H__
#include "misc.h"
typedef struct motor_qei motor;
struct motor_qei {
// qei position parameters
volatile int previous_cnt; // previous (relative) position counter of quadrature input
volatile long pos_cnt; // absolute position counter
// move controlling parameters
long goal_pos; // goal position
int set_speed; // desired speed of the motor during the motion
// internally controlled variables
long moving_pos; // current "desired" position during move
int moving_speed; // current "desired" moving speed of the motor
volatile int current_speed; // real speed of the motor
volatile int current_accel; // current acceleration of the motor shaft
int resolution_error; // compensates for rounding errors
uint8 moving_en; // enable move
// pid control in the "stiff" region
int speed_pgain; // speed proportional error gain
int speed_igain; // speed integrated error gain
int speed_dgain; // speed derivative error gain
long i_error; // speed integral error
int prev_p_error; // previous proportional error, used to compute the derivative error
uint8 update_i_error; // in compliant mode, integral error may not wind-up
// compliant mode, "damped spring" dynamics
int compliance_preload; // spring pretension, in this "stiff" region, pid is applied
int compliance_gain; // spring stiffness
int compliance_damping; // spring damping factor
unsigned int max_trq; // maximum torque setting
// control output parameters
long output_trq; // current torque request
// motor limits
long pos_limit_CW; // maximum clock wise allowed position
long pos_limit_CCW; // maximum counter clock wise allowed position
int max_speed; // maximum speed the motor may reach
unsigned int max_accel; // maximum acceleration rate
};
//void update_position_and_speed(motor *M, int pos_cnt);
//inline the function since it is in an interruption. The faster the better
#define MOTORCONTROL_UPDATE_POSITION_AND_SPEED( M, pos_cnt_val) do{\
int _MC_tmp_speed = pos_cnt_val - M->previous_cnt;\
M->current_accel = _MC_tmp_speed - M->current_speed;\
M->current_speed = _MC_tmp_speed;\
M->previous_cnt = pos_cnt_val;\
M->pos_cnt += M->current_speed;\
}while(0)
void init_motor( motor *M);
void M1_load_control_table_settings(void);
void M2_load_control_table_settings(void);
uint8 set_motor_limits( motor *M, long pos_limit_CW, long pos_limit_CCW, unsigned int max_speed);
uint8 motor_position_control( motor *M, long new_pos, int new_speed);
uint8 motor_speed_control( motor *M, int speed);
uint8 motor_smooth_position_control( motor *M, long next_pos, long period);
void motorcontrol_main(void);
void motorcontrol_main_update_control_table(void);
// internal processes
void update_moving_position( motor *M);
void M1_compute_output(void);
void M2_compute_output(void);
unsigned int M1_trq_to_pwm(long desired_trq, uint8 force_fast_decay);
unsigned int M2_trq_to_pwm(long desired_trq, uint8 force_fast_decay);
#endif // __MOTORCONTROL_H__
Event Timeline
Log In to Comment