[BC2D-POS] initial commit
This commit is contained in:
@@ -16,7 +16,7 @@ uint8_t motion_enable_flag;
|
||||
|
||||
void by_motion_set_pwm_m1(int32_t pwm_duty)
|
||||
{
|
||||
pwm_duty = clip_s32(pwm_duty, -449, 449); // 不可以拉满哦
|
||||
pwm_duty = clip_s32(pwm_duty, -440, 440); // 不可以拉满哦
|
||||
pwm_duty += 499;
|
||||
|
||||
// 互补 pwm 输出,499 为中值
|
||||
@@ -25,7 +25,7 @@ void by_motion_set_pwm_m1(int32_t pwm_duty)
|
||||
|
||||
void by_motion_set_pwm_m2(int32_t pwm_duty)
|
||||
{
|
||||
pwm_duty = clip_s32(pwm_duty, -449, 449); // 不可以拉满哦
|
||||
pwm_duty = clip_s32(pwm_duty, -440, 440); // 不可以拉满哦
|
||||
pwm_duty += 499;
|
||||
|
||||
// 互补 pwm 输出,499 为中值
|
||||
@@ -36,7 +36,7 @@ int16_t by_motion_get_speed_m1(void)
|
||||
{
|
||||
#define alpha (0.1f)
|
||||
static float last_speed = 0.0f;
|
||||
param_m1.real_speed = alpha * last_speed + (1.0f - alpha) * (float)(-1 * (int16_t)tmr_counter_value_get(TMR2));
|
||||
param_m1.real_speed = alpha * last_speed + (1.0f - alpha) * (float)(+1 * (int16_t)tmr_counter_value_get(TMR2));
|
||||
last_speed = param_m1.real_speed;
|
||||
tmr_counter_value_set(TMR2, 0);
|
||||
return (int16_t)param_m1.real_speed;
|
||||
@@ -100,13 +100,13 @@ void by_motion_run(void)
|
||||
{
|
||||
if (motion_enable_flag) {
|
||||
by_motion_get_speed_m1();
|
||||
by_motion_get_speed_m2();
|
||||
// by_motion_get_speed_m2();
|
||||
|
||||
PID_Compute(&pid_m1);
|
||||
PID_Compute(&pid_m2);
|
||||
// PID_Compute(&pid_m2);
|
||||
|
||||
by_motion_set_pwm_m1((int32_t)param_m1.out_pwm);
|
||||
by_motion_set_pwm_m2((int32_t)param_m2.out_pwm);
|
||||
// by_motion_set_pwm_m2((int32_t)param_m2.out_pwm);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,9 +12,9 @@ typedef struct by_motor_param {
|
||||
float out_pwm;
|
||||
} by_motor_param;
|
||||
|
||||
#define BY_MOTION_DEFAULT_KP_M1 (5.0f)
|
||||
#define BY_MOTION_DEFAULT_KI_M1 (100.0f)
|
||||
#define BY_MOTION_DEFAULT_KD_M1 (0.0f)
|
||||
#define BY_MOTION_DEFAULT_KP_M1 (10.0f)
|
||||
#define BY_MOTION_DEFAULT_KI_M1 (80.0f)
|
||||
#define BY_MOTION_DEFAULT_KD_M1 (0.08f)
|
||||
#define BY_MOTION_DEFAULT_KP_M2 (5.0f)
|
||||
#define BY_MOTION_DEFAULT_KI_M2 (100.0f)
|
||||
#define BY_MOTION_DEFAULT_KD_M2 (0.0f)
|
||||
|
||||
Reference in New Issue
Block a user