containsmachine

obedient dog

 
Overview
@TOC

Function description

Quadruped robot: currently supports voice control to move forward, backward, turn left, turn right, twist, shake hands, jump, etc.; supports AP mode, connect to hotspots with a terminal, and access web pages for control; supports control using HC05 and Bluetooth debugger ;OLED expression display and ultrasonic obstacle avoidance are still being optimized. (Optimization completed, see the demonstration video below for the final effect)

Finished product display

Video display

The final video is attached below (the web page in the video is not the final version. For the final version, see the introduction to the web server chapter below). The original power supply was two 18650 batteries, but unfortunately one of the 18650 batteries died, so we had to use The power bank was used for power supply, but the current was obviously not enough, and the effect was not very satisfactory. Then, in response to the comments on Station B, the wake word for voice recognition was modified. (Orange, don’t hit me)
Other study works:
1. [Hi3861+oled playback animation-Bilibili] The refresh rate is close to 25 frames.

image display

Looking down:
43DCE3019E22D4418AB3809058E354CF.jpg#pic_center =30x30
Handheld:
mmexport1657534708819.jpg#pic_center =30x30
Add OLED to display small expressions ( inject soul ):
1d7235507090f4f9.jpg
6485cb6e7f3f3389.jpg
mmexport1658027292998.jpg

Hardware introduction

Power supply section

Since the entire project needs to drive 9 servos and requires a relatively large current, two 18 (diameter) 65 (length) 0 (cylindrical) lithium batteries are used for power supply. The power supply part mainly uses 12V-5V and 5V-3.3V. LDO (there is an optimization point here. The author's diagram at the time was simple and all LDOs were used. The actual heat generation was still serious. Later, he planned to switch to DCDC for power supply).

Manual reference circuit:

LM1084 (mall material number: C259973):
image.png#pic_center =30x30
UZ1084: (Mall material number: C84897)
image.png#pic_center =30x30

Actual use of power circuits

image.png#pic_center =30x30

Main control circuit

The main control uses Chuanzhi Education's HI3861 module (mall part number C2923578). This module has a built-in minimum system circuit, which simplifies the design of this part of the circuit. It only needs to add an additional reset circuit and a 100nF bypass in the power supply part. The circuit capacitor C7 (large capacitor filters out low-frequency noise, small capacitor filters out high-frequency noise) is sufficient.
image.png#pic_center =30x30

Download circuit

In the last Hongmeng training camp, the CH340 was not added and required external wiring. I had to connect it to someone, and learned from the pain. I added the CH340G module. Since the Typec interface is used, two resistors are required on CC1 and CC2. It is convenient for computer recognition. If it is not added, it may not be recognized. In addition, Hi3861 is a 3.3V voltage reference. In order to ensure a unified voltage level, the CH340G here uses a 3.3V power supply (in the last issue, the author had the experience of failed programming with a 5V power supply), so the corresponding V3 port must also be connected to a 3.3V power supply instead of a 5V power supply. That's the way it was.
image.png#pic_center =30x30

Physical PCB

133B96AA1C2C82CE8AB609A12310D896.jpg
image.png

Servo drive module

Since the PCA9685 mall did not have it in stock, I checked the price on Xobao. It cost about the same amount of money to buy a chip and a module. With the attitude of increasing the success rate, I bought the module.
image.png#pic_center =30x30

Voice recognition module

Speech recognition uses the Lu Xiaoban speech recognition module. Official introduction:
ASR-01 is an artificial intelligence chip dedicated to voice processing. It can be widely used in home appliances, home furnishings, lighting, toys and other product fields to realize voice communication.
Interactive control.
ASR-ONE has a built-in self-developed brain neural network processor BNPU, which supports local speech recognition within 200 command words. It has built-in CPU core and high-performance low-power Audio Codec module, and integrates multiple UART, IIC, PWM, GPIO and other peripherals. Control interface can develop various cost-effective single-chip intelligent voice product solutions.
E4E5D2BF63C2645A885DB989FE59BD89.jpg#pic_center =30x30
If you want to buy, click here - "LU-ASR01 Lu Xiaoban Intelligent Speech Recognition Module offline recognizes custom terms far better than LD3320" They have recently released a PRO version, which is said to support voiceprint recognition. I haven't bought it yet. Try it out, and interested students can learn about it on their own.

Ultrasonic module

Here the author is using the 2022 ultrasonic ranging module, link: HC-SR04 ultrasonic sensor is compatible with UNO R3/51/STM32 . The module supports ordinary GPIO mode, IIC mode, UART mode, and 1-Wire mode. Due to the serial port and IIC has been used elsewhere, so you can only choose GPIO mode or 1-Wire mode. The author is using GPIO mode and does not need to change the resistor. If other modes are used, modifications need to be made according to the operation manual.
tb_image_share_1658412606558.jpg

Other things to note

It may be due to the influence of the BootLoader of this module. During power-on and programming, if other pins are connected to the module, it will cause garbled code and failure to reset. Therefore, when designing the circuit, try to use rows for IO use. The pin headers are used instead of being welded in the circuit. For example, if the TX and RX of serial port 1 have been connected to CH340 before powering on, there may be problems such as being unable to start, reset, and burn.

Software Description

main frame

The main body of the program still uses the official example of Chuanzhi. On this basis, hundreds of modifications have been made, mainly by adding a serial port task and action logic.image.png
static void UART_Task(void)
{
IotUartAttribute uart_attr = {
//baud_rate: 9600
.baudRate = 9600,

//data_bits: 8bits



.dataBits = 8,



.stopBits = 1,



.parity = 0,



.rxBlock = 0,



.txBlock = 0,



};



//Initialize uart driver



IoTUartInit(HI_UART_IDX_1, &uart_attr);



while (1)



{



printf("======================================== ");



printf("SIZU_example* ");



printf("======================================== ");



// //Send data through serial port 1



// IoTUartWrite(HI_UART_IDX_1, (unsigned char *)data, strlen(data));



//Receive data through serial port 1



IoTUartRead(HI_UART_IDX_1, uart_buff_ptr, UART_BUFF_SIZE);



SIZU_Uart_Cmd((char *)uart_buff_ptr);



printf("Uart1 read data:%s ", uart_buff_ptr);



usleep(500000);



}



}`
Station B, the main reference for action logic - [Metal Servo + 3D Printed Quadruped Robot - Bilibili]
//Front
//------------------ | D1 | -------------------
// -------- --------
// | D4 | | D13 |
// | joint4 | | joint13 |
// ----- -------- --------- -----
// | D5 | | D12 |
// | joint5 | | joint12 |
// -------- --------
// | D11 | | D3 |
// | joint11 | | joint3 |
// ----- -------- --------- -----
// | D12 | | D2 |
// | joint12 | | joint2 |
// -------- --------

语音识别

然后是语音识别,参考的笔者上期鸿蒙做的笔记——OpenHarmony学习笔记——Hi3861+ASR-01的语音识别助手,由于功能比较简单,也就没有去弄数据包,一个简单的开头和一个数字,然后使用atoi函数获取数字,进行判断,最后执行操作即可。
enum{
Get_Down,//趴下
Hand_shake,//握手
Go_Forward,//前进
Go_Backward,//后退
Go_Left,//左转
Go_Right,//右转
Twist_Body,//扭身子
Stretch_Oneself,//伸懒腰
WAIT//d
};

<br>

<br>

//检测串口指令



void SIZU_Uart_Cmd(char *str)



{



char *Str;



unsigned char ID=255;



Str=&str[1];//定位到指令的数字部分“G1”



ID=atoi(Str);



if(strstr((const char *)str,"G")!=NULL) //如果字符串str中包含有“G”



{



switch(ID)



{



case Get_Down: //趴下 G0



sithome();



printf("Get_Down ");



break;



case Hand_shake: // 握手G1



wink(10);



printf("Handshake ");



break;



case Go_Forward: // 前进G2



forward(5);



printf("Go_Forward ");



break;



case Go_Backward: // 后退G3



backward(5);



printf("Go_Backward ");



break;



case Go_Left: // 左转G4



leftturn(5);



printf("Go_Left ");



break;



case Go_Right: // 右转G5



rightturn(5);



printf("Go_Right ");



break;



case Twist_Body: // 扭身子



twist();



printf("LED_Add ");



break;



case Stretch_Oneself: //伸懒腰



printf("LED_Reduce ");



stand3();



break;



default:



printf("%s ERROR",str);



standhome();//站立



break;



}



}



memset(uart_buff,0,sizeof(uart_buff));



}
OLED显示表情,这个需要找到表情包GIF然后分离出单帧表情,取模,显示,详细的取模过程参考博客0.96寸OLED取模教程(图片、汉字)+ 代码

语音识别代码

语音识别使用的是天问的鹿小班模块,内置图形化编程模块,YYDS,会拖动模块就可以了,想玩语音识别的,强烈推荐此款。
image.png

超声波测距流程

这里笔者使用的是GPIO模式,利用两个GPIO口进行控制和捕获,进而计算出距离,详细介绍请参考笔者的博客——OpenHarmony南向学习笔记——Hi3861+HC-SR04超声波检测

通信流程

根据厂商资料可以知道,该模块的通信流程如下:
1.主控芯片与TRIG连接的IO配置为输出模式,与ECHO连接的IO配置为输入模式;
2.MCU给TRIG引脚输出一个大于10us的高电平脉冲;
3.模块通过ECHO脚返回一个高电平脉冲信号;
4.主控记录ECHO脚高电平脉冲时间T并代入公式计算。

代码

// An highlighted block

#define Echo 8 //Echo //GPIO8
#define Trig 7 //Trig //GPIO7
#define GPIO_FUNC 0

float GetDistance (void) {
static unsigned long start_time = 0, time = 0;
float distance = 0.0;
IotGpioValue value = IOT_GPIO_VALUE0;
unsigned int flag = 0;
/*
=============== GPIO通信模式流程 1初始化GPIO========================================
*/
IoTIoSetFunc(Echo, GPIO_FUNC);//设置Echo连接IO为普通GPIO模式,无复用
IoTGpioSetDir(Echo, IOT_GPIO_DIR_IN);//设置Echo连接IO为输入模式
IoTGpioSetDir(Trig, IOT_GPIO_DIR_OUT);//设置Trig连接IO为输出模式
/*
=============== GPIO通信模式流程 2输出起始信号========================================
*/
IoTGpioSetOutputVal(Trig, IOT_GPIO_VALUE1);//拉高Trig
IoTUdelay(20);//20us
IoTGpioSetOutputVal(Trig, IOT_GPIO_VALUE0);//拉低Trig
/*
=============== GPIO通信模式流程 3检测Echo脚输出的高电平时间========================================
*/
while (1) {
IoTGpioGetInputVal(Echo, &value);//读取Echo脚的电平状态
if ( value == IOT_GPIO_VALUE1 && flag == 0) {//如果为高
start_time = IoTGetUs();//获取此时时间
flag = 1;
}
if (value == IOT_GPIO_VALUE0 && flag == 1) {//高电平结束变成低电平
time = IoTGetUs() - start_time;//计算高电平维持时间
start_time = 0;
break;
}
}
/*
=============== GPIO通信模式流程 4代入公式计算========================================
*/
distance = time * 0.034 / 2;
// printf("distance is %f ",distance);
return distance;
}

网页服务器

这里的网页部分也是在传智的Demo上修改的,由于笔者之前没有学过HTML和JavaScript的知识,在B站大学找了个速成教程,学了一下大概明白了原理,这里把视频链接贴给大家想要学习的自己去看吧——【ESP32创建HTTP服务器,Arduino开发,不会C语言、HTML也能轻松上手,超简单!-哔哩哔哩】。看完UP的视频就可以大致看明白源代码了,进而就可以进行修改了,笔者修改后的界面如下,左侧是后端代码,右侧是服务器端的代码。
image.png
终端打开效果如下,经过验证,所有功能正常。
Screenshot_20220724_121915_com.huawei.browser.jpg
HTML的代码:
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8">
<title>听话的狗子</title><style> body {user-select: none;text-align: center;}
table {margin: 0 auto} td div {width: 150px;height: 150px;border: 1px solid darkgrey;display: flex;align-items: center;justify-content: center;color:deepskyblue;}
#s {background-color: red;color: white;} td div:active {background: yellow;color: white;}
button {margin: 0.5rem;width: 9rem;height: 3rem;font-size: 1.2rem;border-radius: 1rem;}
button:hover {border-radius: 1rem;background-color: green;color: yellow;}
</style></head><body><h1>网页控制</h1>
<button id="c">安装模式</button><button id="a">第一组动作</button><button id="b">第二组动作</button><br><br>
<button id="d">前进</button><br data-tomark-pass><br data-tomark-pass>
<button id="e">左转</button>
<button id="f">右转</button><br data-tomark-pass><br data-tomark-pass>
<button id="g">后退</button><br data-tomark-pass><br data-tomark-pass>
<button id="h">趴下</button><button id="i">握手</button><button id="j">伸懒腰</button><button id="k">扭身子</button>
<br data-tomark-pass><br data-tomark-pass>
<script>
function u(p) {return `${p}`;}
function g(i) {return document.getElementById(i);}
function fe(e, f){e.addEventListener('click', function (e) {/* do something*/f();});}
function fg(u, f) {let x = new XMLHttpRequest();
x.onreadystatechange = function () {if (this.readyState == 4 && this.status == 200) {f(x);}};
x.open("GET", u, true);x.send();}
function fp(u, d, f, p) {let x = new XMLHttpRequest();
if (p) {x.upload.addEventListener('progress', function (e) {p(e);});}
x.onreadystatechange = function () {if (this.readyState == 4 && this.status == 200) {f(x);}};
x.open('POST', u, true);x.timeout = 45000;x.send(d);}
fe(g('a'), () => {fg(u('/dog/first'), () => {});});
fe(g('b'), () => {fp(u('/dog/second'), () => {});});
fe(g('c'), () => {fp(u('/dog/init'), () => {});});
fe(g('d'), () => {fp(u('/dog/forward'), () => {});});
fe(g('e'), () => {fp(u('/dog/left'), () => {});});
fe(g('f'), () => {fp(u('/dog/right'), () => {});});
fe(g('g'), () => {fp(u('/dog/backward'), () => {});});
fe(g('h'), () => {fp(u('/dog/fall'), () => {});});
fe(g('i'), () => {fp(u('/dog/handshake'), () => {});});
fe(g('j'), () => {fp(u('/dog/stretch'), () => {});});
fe(g('k'), () => {fp(u('/dog/twist'), () => {});});
</script></body></html>

Bluetooth APP

Since the author has not learned how to make APPs, the host computer produced here is a Bluetooth debugger. The function of this debugger is quite powerful. If you are interested, you can try it.
image.png#pic_center =60x60
By the way, does anyone have a good tutorial on how to make an APP? It’s a simple PC-based one.

Mechanical structure

It was also the first time for the author to draw a 3D structural part by myself, and it was not very good. I then drew a hammer, and then I felt that the structure I drew was not very reliable, so I went to the seafood market and found this one, which has the same characteristics. Students who are troubled can go and take a look, 38 meters - a 3D printed version of a quadruped robot (the printed part is not the complete machine, so you need to bring your own electronic parts, screws, etc.) .
image.png
image.png

bill of materials

Two 18650 or 2S lithium batteries cost about 30-40, plus the OLED, ultrasonic module, M3 screws, nuts, copper pillars, modules, and chips cost about 200.

Summarize

Thanks to Lichuang EDA, Chuanzhi, Dark Horse Programmer, and CSDN for providing this event. I learned a lot of knowledge that I had not encountered before and benefited a lot from this event.

study notes

There are hundreds of millions of Hongmeng study notes here. Everyone is welcome to exchange and study here. If there are any mistakes, please send me a private message to teach me how to correct them, otherwise I will mislead others.

参考设计图片
×
 
Related Devices
Devices Class introduce Datasheet
CA45-A-16V-22uF-K Tantalum capacitor Download
RST22UF16V024 Patch type aluminum electrolytic capacitors Download
RMC 0402 100K F N SMD resistor Download
0201X473K100NT Download
 
Search Datasheet?

Supported by EEWorld Datasheet

Forum More
Update:2024-11-22 18:53:41

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号