环境准备
前置条件
- 按照官方指导文档完成CANN包安装
- CANN版本需要>=5.0.4.alpha001(本教程使用5.04alpha005)
软件准备
源码包:samples: CANN Samples (gitee.com)
模型:cplusplus/contrib/Ascbot/README_CN.md · Ascend/samples - Gitee.com
建议下载模型,权重和配置文件后本地使用atc转换为om文件,直接下载om文件可能会有问题
模型,权重,配置文件直接放在/home/HwHiAiUser/samples/cplusplus/contrib/Ascbot/
目录下
转换的om文件放在/home/HwHiAiUser/samples/cplusplus/contrib/Ascbot/model
下,注意model
文件夹中的.keep
不能删除
#检测小车前方是否有跌落危险
atc --model="collision_avoidance_model.prototxt" --weight="collision_avoidance_model.caffemodel" --soc_version=Ascend310 --framework=0 --output="collision_avoidance_model" --insert_op_conf=insert_op_collision_avoidance.cfg
#检测车道线,实现循道行驶
atc --model="road_following_model.prototxt" --weight="road_following_model.caffemodel" --soc_version=Ascend310 --framework=0 --output="road_following_model" --insert_op_conf=insert_op_road_following.cfg
#检测小车前方物体
atc --model="road_object_detection_deploy.prototxt" --weight="road_object_detection_deploy.caffemodel" --soc_version=Ascend310 --framework=0 --output="road_object_detection_deploy" --insert_op_conf=insert_op_road_object_detection_deploy.cfg
样例部署
设置环境变量,以防后面冲突,这里设置临时环境变量
export DDK_PATH=$HOME/Ascend/ascend-toolkit/latest/arm64-linux
export NPU_HOST_LIB=$DDK_PATH/runtime/lib64/stub
#如果是3.0.0版本,此处 DDK_PATH环境变量中的arm64-liunx应修改为 arm64-linux_gcc7.3.0。
#可以在命令行中执行uname -a,查看开发环境和运行环境的cpu架构。如果回显为x86_64,则为x86架构。如果回显为arm64,则为Arm架构。
编译运行
#切换目录,创建目录用于存放编译文件。
cd $HOME/samples/cplusplus/contrib/Ascbot
mkdir -p build/intermediates/host
#切换到 build/intermediates/host 目录,执行cmake生成编译文件。
cd build/intermediates/host
make clean
cmake ../../../src -DCMAKE_CXX_COMPILER=aarch64-linux-gnu-g++ -DCMAKE_SKIP_RPATH=TRUE**
#执行make命令,生成的可执行文件main在 Ascbot/out 目录下
make
#运行
./main -Channel-1
#后面的Channel参数根据实际情况修改
常见的Error解决办法
1.代码在终端运行,小车没有反应,更换新的wheel.cpp
(见附录),之后在重新编译运行,注意不是只改0x60,建议全部复制粘贴
2.[ERROR] UART Can't open uart0 print!
cd /dev
su root
chmod 777 * #这句输入后有一个报错不用管
chmod 777 t*
3.[ERROR] post_data.ip_address------------- XXX.XXX.XXX.XXX
此问题是没有连接手机端,可以暂时忽略
4.还有其他报错欢迎留言
手机端控制
下载地址:文件分享 (weiyun.com)
先运行./main
文件后,再进行手机连接,代码不能中断,IP使用ifconfig
进行查看,需要连在同一个路由器WIFI下。
附录
wheel.cpp
#include <memory>
#include <fstream>
#include <sstream>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/select.h>
#include <sys/time.h>
#include <errno.h>
#include <string.h>
#include "wheel.h"
const unsigned char slave_addr = 0x40;
const unsigned char stop[70] = {0x00,0x04,0xe2,0xe4,0xe8,0xe0,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x10,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x10,0x00,0x00,
0x00,0x10,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x10,0x00,0x00,
0x00,0x10,0x00,0x00,0x00,0x10};
wheel::wheel(void)
{
}
wheel::~wheel(void)
{
}
int wheel::wheel_init(void)
{
for(unsigned char i=0;i<70;i++)
{
if(i2c_ctrl.atlas_i2c_write(slave_addr,i,stop[i])!=0)
{
break;
}
}
return 0;
}
int wheel::wheel_left_move(int direction,unsigned char speed)
{
if(speed>0x1f)
speed = 0x1f;
if(direction == 1)
{
INFO_LOG(" wheel left move:direction == 1\n");
i2c_ctrl.atlas_i2c_write(slave_addr,0x14,0x00);//LED3_OFF_L
i2c_ctrl.atlas_i2c_write(slave_addr,0x15,0x00);//LED3_OFF_H
i2c_ctrl.atlas_i2c_write(slave_addr,0x18,4095&0xff);//LED4_OFF_L
i2c_ctrl.atlas_i2c_write(slave_addr,0x19,4095>>8);//LED4_OFF_H
}
else if(direction == -1)
{
INFO_LOG(" wheel left move:direction == -1\n");
i2c_ctrl.atlas_i2c_write(slave_addr,0x14,4095&0xff);//LED3_OFF_L
i2c_ctrl.atlas_i2c_write(slave_addr,0x15,4095>>8);//LED3_OFF_H
i2c_ctrl.atlas_i2c_write(slave_addr,0x18,0x00);//LED4_OFF_L
i2c_ctrl.atlas_i2c_write(slave_addr,0x19,0x00);//LED4_OFF_H
}
//i2c_ctrl.atlas_i2c_write(slave_addr,0x3d,speed);
i2c_ctrl.atlas_i2c_write(slave_addr,0x1c,(speed*120)&0xff);//LED5_OFF_L PWMB
i2c_ctrl.atlas_i2c_write(slave_addr,0x1d,(speed*120)>>8);//LED5_OFF_H
return 0;
}
int wheel::wheel_right_move(int direction,unsigned char speed)
{
if(speed>0x1f)
speed = 0x1f;
if(direction == 1)
{
INFO_LOG(" wheel right move:direction == 1\n");
i2c_ctrl.atlas_i2c_write(slave_addr,0x0c,0x00);//LED1_OFF_L
i2c_ctrl.atlas_i2c_write(slave_addr,0x0d,0x00);//LED1_OFF_H
i2c_ctrl.atlas_i2c_write(slave_addr,0x10,4095&0xff);//LED2_OFF_L
i2c_ctrl.atlas_i2c_write(slave_addr,0x11,4095>>8);//LED2_OFF_H
}
else if(direction == -1)
{
INFO_LOG(" wheel right move:direction == -1\n");
i2c_ctrl.atlas_i2c_write(slave_addr,0x0c,4095&0xff);//LED1_OFF_L
i2c_ctrl.atlas_i2c_write(slave_addr,0x0d,4095>>8);//LED1_OFF_H
i2c_ctrl.atlas_i2c_write(slave_addr,0x10,0x00);//LED2_OFF_L
i2c_ctrl.atlas_i2c_write(slave_addr,0x11,0x00);//LED2_OFF_H
}
//i2c_ctrl.atlas_i2c_write(slave_addr,0x29,speed);
i2c_ctrl.atlas_i2c_write(slave_addr,0x08,(speed*120)&0xff);//LED0_OFF_L PWMA
i2c_ctrl.atlas_i2c_write(slave_addr,0x09,(speed*120)>>8);//LED0_OFF_H
return 0;
}
标签:slave,addr,ctrl,小车,0x00,样例,开源,atlas,i2c
From: https://www.cnblogs.com/qzt2cool/p/18303149