feat:add motor and encoder based on can-bus and add a kinematics#39
feat:add motor and encoder based on can-bus and add a kinematics#39Soil-L wants to merge 6 commits intoRT-Thread-packages:masterfrom Soil-L:add_can_driver
Conversation
sogwms
left a comment
There was a problem hiding this comment.
请规范代码风格,不要使用 tab
新添加的文件在头部加上版权声明(参考其他文件)
|
ping @Soil-L |
|
@Soil-L 请问你在rt-robot微信群里吗?我最近也在捣鼓DJI的配件,想和你交流一下 |
考试月忙于复习,不好意思!现在考完了,我尽快改! |
我在一个叫 RT-Thread官方DIY群 的微信群里昵称是Soil_L,不过我水平很有限,请多指教哈 |
| { | ||
| // return resolution per minute | ||
| res_rpm = encoder_measure_cps(enc) * 60 / enc->pulse_revol; | ||
| } |
There was a problem hiding this comment.
为什么要做这个修改? 对can电机获取编码器信息有帮助吗? 对于像大疆can电机 encoder_measure_cps 才是障碍吧, 抽象程度不够
There was a problem hiding this comment.
因为对于利用计数脉冲的编码器来说有采样周期,而对于利用通信协议传输数据的编码器来说没有采样周期。所以在这里有一个判断,如果sample_time>0则有采样周期,计算res_rpm的方法不变,如果sample_time<=0则表示没有采样周期,res_rpm由pulse_count直接得到。
| }; | ||
| typedef struct can_encoder *can_encoder_t; | ||
|
|
||
| can_encoder_t can_encoder_create(char *can,struct rt_can_filter_config cfg,rt_uint32_t Baud,rt_sem_t* rx_sem); |
There was a problem hiding this comment.
xxx_encoder_create 是面向用户的 rx_sem 是否真的必须? 合理?
另外有点疑惑,这个测试过吗,可以正常工作?
There was a problem hiding this comment.
- 这份提交希望的是对基于can通信的电机设备和编码器设备都能适配,但是无法统一每一种can设备的通信协议,所以每次接收后解包必须由用户完成,所以需要用信号量通知解包开始。
- 对于测试,其实issue提交之时我的项目就有急迫的需求,所以很快就按照rt-robot的框架写好了,至少正常运行了1个月,但是,没有没有整合进rt-robot中运行,相当于我自己的用户代码,和我其他代码有一些耦合。提交的时候做了一下修改,其中主要是变量名,还有运动学模型的选择那一块。我可以把建立底盘模型的那一块代码给你看。
There was a problem hiding this comment.
建议这样, 如果通用的不能完整(或很好地)整出来, 那就先直接上专用的,比如直接就针对 C620 电调, 给用户的接口也可以更易用
| new_encoder->enc.destroy = can_encoder_destroy; | ||
| new_encoder->Baud = Baud; | ||
| new_encoder->rx_sem = rx_sem; | ||
| rx_sem_g = *rx_sem; |
There was a problem hiding this comment.
对于多实例的 encoder, 全局 sem 是个bug。完全可以不用这样做
There was a problem hiding this comment.
本身信号量是一个指针,多个编码器又要用到同一个信号量,所以我传入的是信号量指针,所以这里是指针的指针
There was a problem hiding this comment.
不管是结构体或结构体指针,它是全局的。 如果确定所有情况下用到的都是同一个信号量,为什么还需要用户创建
| * Change Logs: | ||
| * Date Author Notes | ||
| * 2019-07-17 Wu Han The first version | ||
| * 2019-11-14 Soil_L add four wheel omnidirectional |
| static rt_err_t can_motor_set_speed(void *mot, rt_int16_t thousands) | ||
| { | ||
| can_motor_t mot_sub = (can_motor_t)mot; | ||
|
|
||
| if(mot_sub->min_num > thousands) | ||
| { | ||
| thousands = mot_sub->min_num; | ||
| } | ||
| else if(mot_sub->max_num < thousands) | ||
| { | ||
| thousands = mot_sub->max_num; | ||
| } |
There was a problem hiding this comment.
额, 此处的 thousands 默认即暗示设定范围为 -1000 ~ 1000, 将此映射到实际可设置范围即可。 可参考其他已有 motor
There was a problem hiding this comment.
这里的thousands是什么含义?我的理解是控制器计算完之后给电机执行的输出
There was a problem hiding this comment.
是的,但值的范围是确定的。 打个比方, 电机是小弟,上面的大哥给它设定值让它运转。 小弟和大哥都公认 设定值的范围是 -1000~+1000. 小弟(电机)多种多样(最大转速等)。 但都知道 +-1000 对应自己的最大转速, 0是停止
|
|
||
| mot_sub->msg->data[(mot_sub->mot_id -1)*2] = thousands>>8; | ||
| mot_sub->msg->data[(mot_sub->mot_id -1)*2+1] = thousands; | ||
| rt_size_t size = rt_device_write(mot_sub->can_dev, 0, mot_sub->msg, sizeof(*(mot_sub->msg)) ); |
There was a problem hiding this comment.
这是只针对大疆can电机的协议吗,是的话文件名等应该更具体一点 比如 dji_can_motor
There was a problem hiding this comment.
想的是对所有用can通信的电机和编码器。测试的时候用的是大疆M3508电机(C620电调)
There was a problem hiding this comment.
不是很了解 can 电机 不知 大疆系的can电机协议是否都相同(似)可统一,非大疆的can电机有没有,协议怎样。 可以的话还是建议在能保证完整性的前提下提高适用层次。 建议针 c602 或 大疆系?
| }; | ||
| typedef struct can_motor *can_motor_t; | ||
|
|
||
| can_motor_t can_motor_create(char *can,struct rt_can_filter_config cfg,rt_uint32_t Baud,rt_can_msg_t msg,rt_int16_t max_num,rt_int16_t min_num,rt_uint8_t mot_id); |
There was a problem hiding this comment.
同样的问题 api是否合适? 需要msg?需要 maximum?
还有想问下这是针对哪种can电机的? 还是通用的?
There was a problem hiding this comment.
- 因为常常是多个电机挂在同一个can网络上,用ID来区分不同的电机数据,所以希望用户先把每一个电机的msg里的ID设置好
- 不同的电机有不同的最大设置值,max_num是为了适配不同的电机的最大设置值
Uh oh!
There was an error while loading. Please reload this page.