文章目录

0 前言1 简介2 主要器件3 实现效果4 硬件设计总体框架**AB32VG1主控MCU**

5 软件说明总体框架

6 部分核心代码7 最后

0 前言

 这两年开始毕业设计和毕业答辩的要求和难度不断提升,传统的毕设题目缺少创新和亮点,往往达不到毕业答辩的要求,这两年不断有学弟学妹告诉学长自己做的项目系统达不到老师的要求。

为了大家能够顺利以及最少的精力通过毕设,学长分享优质毕业设计项目,今天要分享的是

 基于单片机的自动写字机器人设计与实现

磊学长这里给一个题目综合评分(每项满分5分)

难度系数:3分工作量:3分创新点:5分

1 简介

基于RTthread的写字机控制系统,采用独立研发的运动控制系统,结合RTT的多线程,将运动控制分解,速度前馈、折线速度平滑优化。AB32VG1开发板作为UI交互和sd卡gc文件读取,采用串口将运动命令发送给STM32。STM32负责将串口接收到的G命令进行解析,运动计算、控制输出P合适的PWM频率和脉冲个数给4个电机。运动控制算法完全独立创作。 Halo项目是我9月初时候的一个自研3D打印机的固件,前期在工作中接触到Marlin(一款优秀的开源3D打印固件,提供了丰富的扩展功能,拥有完整成熟的生态),遂想自研一款基于国产芯片和操作系统的3D打印系统,能提供在咱国产的芯片中方便移植与运行,提供3D打印所需的所有功能,降低硬件成本和软件适配成本。

2 主要器件

STM32F4单片机AB32VG1单片机RT-Thread物联网操作系统SD卡文件读取与发送速度前馈、折角优化、加速处理等算法

3 实现效果

4 硬件设计

总体框架

AB32V负责GUI和SD卡文件,STM32负责运动控制

最初设想是采用两块AB32的板子,一个负责GUI人机交互和SD卡文件读取与发送,一块负责接收Gcode命令,完成速度前馈、折角优化、加速处理等算法,实现完整的运动控制算法。但实际在AB32上跑控制时,发现浮点运算会导致异常的问题,同时打印日志都经常遇到栈溢出导致系统崩溃,因此将运动控制算法移植到STM32F4的板子上运行,控制效果良好。

AB32VG1主控MCU

简介

开发板采用中科蓝讯的32位RISC-V指令集的AB32VG1型号MCU,主频120M。MCU有8M的Flash,和192K SRAM。支持3.0V-5.0V供电。 与一般MCU不同的是,这款MCU具有MPU模块,就是电源管理模块,支持Charge电路、BUCK电路、LDO电路等等,手册第十页给出了MPU模块的详细参数。 开发环境搭建

根据官方的指导,使用的是RT-thread官方stduio平台,先更新软件源代码至最新版,下载中科蓝讯软件包,下载RISC-V-GCC工具链,编译程序会用到。

软件包配置

接下来选择我们本次实验用到的软件包,wavplayer软件包、optparse软件包和multibutton软件包,实现通过板载按键控制声音的播放语音量的增减。 然后对软件包进行简单配置,按键的示例代码可以勾选也可以不勾选,后面要对此进行修改,改为评测板上的用户按键,optparse软件包默认即可。

5 软件说明

总体框架

代码树

6 部分核心代码

int main(void)

{

rt_thread_mdelay(1000);

serial_thread_init(NULL);

while(1){

//debug_error("Insufficient system memory");

while(refresh_file_names("/") == 0){

rt_thread_mdelay(1000);

}

uart_lcd_thread_init();

rt_thread_mdelay(100);

gui_into_print_list(NULL);

while(1){

rt_thread_mdelay(1000);;

}

}

g_gcode_ringbuff = ringbuff_create(sizeof(uint8_t), 4096);

if(g_gcode_ringbuff == NULL){

debug_error("Insufficient system memory");

while(1);

}

while(1){

rt_thread_mdelay(1000);

debug_info("rt - thread\r\n");

}

while (1)

{

list_cur_dir_files("/");

if(dfs_file_open(&s_fd, get_cur_dif_file_name(0), O_RDONLY) < 0){

debug_info("open file %s error", get_cur_dif_file_name(0));

continue;

}

debug_info("open file %s ok", get_cur_dif_file_name(0));

int read_bytes;

uint8_t buff[512];

int idx = 0;

do{

memset(buff, 0, sizeof(buff));

read_bytes = dfs_file_read(&s_fd, buff, sizeof(buff));

while(ringbuff_remin(g_gcode_ringbuff) < read_bytes){

rt_thread_yield();

}

for(int i = 0; i < read_bytes; i++){

ringbuff_push(g_gcode_ringbuff, &buff[i]);

}

}while(read_bytes > 0);

dfs_file_close(&s_fd);

}

return RT_EOK;

}

/* 定时器超时回调函数 */

#if (defined SOC_AB32VG1)

RT_SECTION(".irq.timer")

#endif

static rt_err_t step_run_schdule(rt_device_t dev, rt_size_t size)

{

extern motion_control_t *motion_control;

if((motion_control->motion_step_z.ops->is_motion(&(motion_control->motion_step_z)) == true) ||

(ringbuff_is_empty(motion_control->motion_step_z.step_drv->pulse_list) == false)){

motion_control->motion_step_z.step_drv->ops-> \

timer_schdule(motion_control->motion_step_z.step_drv);

return RT_EOK;

}

motion_control->motion_step_x.step_drv->ops-> \

timer_schdule(motion_control->motion_step_x.step_drv);

motion_control->motion_step_y.step_drv->ops-> \

timer_schdule(motion_control->motion_step_y.step_drv);

motion_control->motion_step_y_1.step_drv->ops-> \

timer_schdule(motion_control->motion_step_y_1.step_drv);

return RT_EOK;

}

/* 初始化挤出机 */

void fdm_extruder_init(void)

{

if(false == temperature_register(&s_temperature_ntc, temperature_type_ntc)){

return;

}

/* 初始化传感器接口 */

if(false == temperature_init(&s_temperature_ntc, /* 描述符 */

TEMPERATURE_NTC_ADC_DEV_NAME, /* 驱动名称 */

TEMPERATURE_NTC_ADC_DEV_CHANNEL, /* 通道号 */

12, /* adc精度 */

ntc_mode_zm_1460, /* ntc传感器型号 */

4700)){ /* 上拉电阻阻值 */

}

}

void fdm_printer_test(void)

{

/* 初始化所有的温度传感器 */

//fdm_extruder_init();

rt_pin_mode(49, PIN_MODE_OUTPUT);

rt_pin_write(49, PIN_HIGH);

#if 0

heater_t *heater;

heater = heater_create(pid_type_position);

/* 设置pid的三个参数,输出最大、最小值 */

heater->pid->ops->init(heater->pid, 0.5, 0.5, 1, 100, 0);

/* 设置调节的目标值 */

heater->pid->ops->target_set(heater->pid, 30);

/* 绑定温度传感器,设置pid的计算周期 */

heater->ops->init(heater, 1, true, 3000, &s_temperature_ntc);

/* 开始软件定时器 */

heater->ops->start(heater);

#endif

hard_task_t *hard_task;

/* 创建硬实时任务对象 */

hard_task = hard_task_creater();

hard_task->ops->init(hard_task, STEP_SCHDULE_HWTIMER_DEV_NAME,

STEP_SCHDULE_TIMER_FREQ);//

hard_task->ops->set_run(hard_task, step_run_schdule);

hard_task->ops->start(hard_task, STEP_SCHDULE_FREQ);

}

7 最后

 项目分享与指导:https://gitee.com/sinonfin/sharing

参考文章

评论可见,请评论后查看内容,谢谢!!!
 您阅读本篇文章共花了: