RT-Thread-packages / rt-robot

a platform in creating new exciting robots
Apache License 2.0
111 stars 62 forks source link

程序中的这个地方是什么意思呢 #46

Open cbwznb opened 1 year ago

cbwznb commented 1 year ago

tangential_vel = angular_vel_z_mins * ((kin.length_x / 2) + (kin.length_y / 2)); 横向轴距和纵向轴距相加除2

cbwznb commented 1 year ago

横向轴距和纵向轴距相加除2是转弯半斤吗?半径为什么是横向轴距和纵向轴距相加除2,谢谢

wuhanstudio commented 1 year ago

这个是针对 Mecanum 轮的速度分解,具体的推导在 PDF 的 eq.14 和 eq.15。

https://research.ijcaonline.org/volume113/number3/pxc3901586.pdf

如果把 Fig. 2 这个 Mecanum 轮小车的参数 Table 1 (alpha, beta, gamma) 带入到 eq.14 和 eq. 15 就得到了 eq. 20 和 eq.21,

image

其中 lx = 横向轴距 / 2, ly = 纵向轴距 / 2,也就是下面代码的实现:

tangential_vel = angular_vel_z_mins * ((kin.length_x / 2) + (kin.length_y / 2));

右边公式红色部分 = (lx+ly) * w = w * ( (x / 2) + (y / 2) )

如果是普通的小车(非 Mecanum 轮),小车无法横向移动 (linear_y=0),也无法原地旋转 (angular_vel_z_mins = 0),其实可以忽略这个公式。

比如在 docs/samples.md 里面,两轮 Ackerman 的小车 (类似自行车) y, z 方向速度都是 0,只能控制前进速度和转角:

    target_velocity.linear_x = 0.00f;
    target_velocity.linear_y = 0;
    target_velocity.angular_z = 0;
    chassis_set_velocity(chas, target_velocity);

针对 Ackerman (自行车) eq. 20 和 eq.21 的实现就变得非常简单:

https://github.com/RT-Thread-packages/rt-robot/blob/master/kinematics/kinematics.c

    x_rpm   = linear_vel_x_mins / kin.wheel_cir;
    y_rpm   = linear_vel_y_mins / kin.wheel_cir;
    tan_rpm = tangential_vel / kin.wheel_cir;

    // front-left motor
    cal_rpm.motor1 = x_rpm - y_rpm (=0) - tan_rpm (=0) = x_rpm;

    // front-right motor
    cal_rpm.motor2 = x_rpm + y_rpm (=0) + tan_rpm (=0) = x_rpm;

    // rear-left motor
    cal_rpm.motor3 = x_rpm + y_rpm (=0) - tan_rpm (=0) = x_rpm;

    // rear-right motor
    cal_rpm.motor4 = x_rpm - y_rpm (=0) + tan_rpm (=0) = x_rpm;
cbwznb commented 1 year ago

老师,你好。按您的讲解,如果是非mecanum,y、z都是0,那比如两轮差速,只有x的转速,两轮转速一样怎么进行转弯了呢?

2223025466 @.***

 

------------------ 原始邮件 ------------------ 发件人: "RT-Thread-packages/rt-robot" @.>; 发送时间: 2023年6月13日(星期二) 晚上6:27 @.>; @.**@.>; 主题: Re: [RT-Thread-packages/rt-robot] 程序中的这个地方是什么意思呢 (Issue #46)

这个是针对 Mecanum 轮的速度分解,具体的推导在 PDF 的 eq.14 和 eq.15。

https://research.ijcaonline.org/volume113/number3/pxc3901586.pdf

如果把 Fig. 2 这个 Mecanum 轮小车的参数 Table 1 (alpha, beta, gamma) 带入到 eq.14 和 eq. 15 就得到了 eq. 20 和 eq.21,

lx = 横向轴距 / 2, ly = 纵向轴距 / 2,也就是下面代码的实现: tangential_vel = angular_vel_z_mins * ((kin.length_x / 2) + (kin.length_y / 2));

如果是普通的小车(非 Mecanum 轮) angular_vel_z_mins = 0,其实可以忽略这个公式。

比如在 docs/samples.md 里面,两轮 Ackerman 的小车 (类似自行车) y, z 方向速度都是 0,只能控制前进速度和转角: target_velocity.linear_x = 0.00f; target_velocity.linear_y = 0; target_velocity.angular_z = 0; chassis_set_velocity(chas, target_velocity);
针对 Ackerman (自行车) eq. 20 和 eq.21 的实现就变得非常简单: x_rpm = linear_vel_x_mins / kin.wheel_cir; y_rpm = linear_vel_y_mins / kin.wheel_cir; tan_rpm = tangential_vel / kin.wheel_cir; // front-left motor cal_rpm.motor1 = x_rpm - y_rpm (=0) - tan_rpm (=0) = x_rpm; // front-right motor cal_rpm.motor2 = x_rpm + y_rpm (=0) + tan_rpm (=0) = x_rpm; // rear-left motor cal_rpm.motor3 = x_rpm + y_rpm (=0) - tan_rpm (=0) = x_rpm; // rear-right motor cal_rpm.motor4 = x_rpm - y_rpm (=0) + tan_rpm (=0) = x_rpm;
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

wuhanstudio commented 1 year ago

老师,你好。按您的讲解,如果是非mecanum,y、z都是0,那比如两轮差速,只有x的转速,两轮转速一样怎么进行转弯了呢?

我前面的 普通的小车(非 Mecanum 轮)例子是指 Ackerman (类似自行车),既无法横向移动 (linear_y=0),也无法原地旋转 (angular_vel_z_mins = 0)。

对于两轮差分的小车,只有后两轮,小车无法横向移动 (linear_y=0),但是可以原地旋转 target_velocity.angular_z 不等于 0,所以:

    // rear-left motor
    cal_rpm.motor3 = x_rpm + y_rpm (=0) - tan_rpm = x_rpm - tan_rpm;

    // rear-right motor
    cal_rpm.motor4 = x_rpm - y_rpm (=0) + tan_rpm = x_rpm + tan_rpm;

可以看到,逆时针为正 (左轮倒转,右轮正转);顺时针为负 (左轮正转,右轮逆转)。

wuhanstudio commented 1 year ago

另外,在例程中可以看到,两轮差分 WHEEL_DIST_X=0,可能需要在源码里提醒,如果动力学模型为 TWO_WD,两轮差分 kin.length_x 需要强制设置为 0。

https://github.com/RT-Thread-packages/rt-robot/blob/master/docs/samples.md

cbwznb commented 1 year ago

好的,老师,我总结了一下。 两轮差速是     // rear-left motor     cal_rpm.motor3 = x_rpm  - tan_rpm;

    // rear-right motor     cal_rpm.motor4 = x_rpm  + tan_rpm;

四轮差速是     // front-left motor     cal_rpm.motor1 = x_rpm  - tan_rpm;

    // front-right motor     cal_rpm.motor2 = x_rpm  + tan_rpm;

    // rear-left motor     cal_rpm.motor3 = x_rpm  - tan_rpm;

    // rear-right motor     cal_rpm.motor4 = x_rpm + tan_rpm;

阿克曼是     // rear-left motor     cal_rpm.motor3 = x_rpm;

    // rear-right motor     cal_rpm.motor4 = x_rpm ;

此处的阿克曼是没有差速的,后面两个轮子速度一样,前轮转向是人为直接给的,没有计算。

mecanum是     // front-left motor     cal_rpm.motor1 = x_rpm - y_rpm - tan_rpm;

    // front-right motor     cal_rpm.motor2 = x_rpm + y_rpm + tan_rpm;

    // rear-left motor     cal_rpm.motor3 = x_rpm + y_rpm - tan_rpm;

    // rear-right motor     cal_rpm.motor4 = x_rpm - y_rpm + tan_rpm;

mecanum三个量就都有了

2223025466 @.***

 

------------------ 原始邮件 ------------------ 发件人: "RT-Thread-packages/rt-robot" @.>; 发送时间: 2023年6月14日(星期三) 晚上7:39 @.>; @.**@.>; 主题: Re: [RT-Thread-packages/rt-robot] 程序中的这个地方是什么意思呢 (Issue #46)

另外,在例程中可以看到,两轮差分 WHEEL_DIST_X=0,可能需要在源码里提醒,如果动力学模型为 TWO_WD,两轮差分 kin.length_x 需要强制设置为 0。

https://github.com/RT-Thread-packages/rt-robot/blob/master/docs/samples.md

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

wuhanstudio commented 1 year ago

没错,可能应该用 前后轮距离 (x = front-rear)左右轮距离 (y = left-right) 来表示更直观,x y 太容易弄混了。

下面这张图上右下角 lx 和 ly 就画在一起了 (感觉论文作者这里自己都弄混淆了)。

image

image

cbwznb commented 1 year ago

老师,还有一个问题,例程中GEAR_RATIO是齿轮减速比吗? c_wheels[0] = wheel_create((motor_t)left_motor,  (encoder_t)left_encoder,  (controller_t)left_pid,  WHEEL_RADIUS, GEAR_RATIO); c_wheels[1] = wheel_create((motor_t)right_motor, (encoder_t)right_encoder, (controller_t)right_pid, WHEEL_RADIUS, GEAR_RATIO);

2223025466 @.***

 

------------------ 原始邮件 ------------------ 发件人: "RT-Thread-packages/rt-robot" @.>; 发送时间: 2023年6月14日(星期三) 晚上10:33 @.>; @.**@.>; 主题: Re: [RT-Thread-packages/rt-robot] 程序中的这个地方是什么意思呢 (Issue #46)

没错,刚发现例程有一个错误,在这个坐标系下,应该是 WHEEL_DIST_Y = 0,也就是 kin.length_y = 0.

可能应该用 前后轮距离 (x = front-rear) 和 左右轮距离 (y = left-right) 来表示更直观,x y 太容易弄混了。

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

wuhanstudio commented 1 year ago

没错,车轮电机初始化可以配置 motor (PWM 输出端口) + encoder (编码器测速) + PID (控制器) + radius (半径) + Gear Ratio (减速比)