[BC2D-POS] initial commit

This commit is contained in:
bmy
2024-05-10 10:54:06 +08:00
parent c9da340c46
commit 1c83cbc70a
12 changed files with 155 additions and 50 deletions

View File

@@ -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);
}
}