JETBOT AI构建指南

这个就是我们目前在官网看见的产品,可以看到还是很简单的。两个差速轮子。一个主板,一个电机驱动模块,一个摄像头

差分驱动器配置,就是两个轮子的转速不一样。
就可以前进,后退,转弯等
霍尔效应传感器轮编码器,这个用来精确控制小车的速度
前置 160° FOV 摄像机
IMU
TOF传感器带来的避障体验
用于电池诊断的各种传感器
后面还可以扩展更多的玩法

这个又是一种机器小车:可以看到是用充电宝驱动的,那我们也可以用充电宝驱动~
https://jetbot.org/v0.4.3/
官方还有文档
https://jupyter.org/
这个就是运行笔记本的核心,我们未来的程序就放到这里运行

可以先在我的主机上面运行一次,先下载

直接运行

我因为以前就有安装过,所以把配置文件直接读入了

应该就是用了一个I2C的小屏幕。来显示IP以及内存大小

这个是构建的模块图,分为硬件软件两个层级
https://github.com/NVIDIA-AI-IOT/jetracerJetRacer 是使用 NVIDIA Jetson Nano 的自主 AI 赛车。这个我在后面会在分析一下~

首先构建车是用的这种小的直流减速电机

以及这样的电机驱动板,有很多来代替的电路板

在连接电源的时候,有这种弯头的选择

这个是2GB的Type-C接口

我们重点说说这个屏幕
https://www.adafruit.com/product/3527购买链接

有一个用于SSD1306芯片组的Python库
背面图

这个小玩意儿是给树莓安装的
sudo apt-get update
sudo apt-get upgrade
sudo pip3 install --upgrade setuptoolssudo
apt-get install python3-pip
以上的脚本是在树莓派内运行的,其他的设备打通小异
cd ~sudo pip3 install --upgrade adafruit-python-shellwget https://raw.githubusercontent.com/adafruit/Raspberry-Pi-Installer-Scripts/master/raspi-blinka.pysudo python3 raspi-blinka.py
以及一会儿问你是不是重新启动,是
以下代码来检查机器的I2C和SPI的功能是不是正常
ls /dev/i2c* /dev/spi*
应该看到响应
/dev/i2c-1 /dev/spidev0.0 /dev/spidev0.1
想
import boardimport digitalioimport busio print("Hello blinka!") # Try to great a Digital inputpin = digitalio.DigitalInOut(board.D4)print("Digital IO ok!") # Try to create an I2C devicei2c = busio.I2C(board.SCL, board.SDA)print("I2C ok!") # Try to create an SPI devicespi = busio.SPI(board.SCLK, board.MOSI, board.MISO)print("SPI ok!") print("done!")python3 blinkatest.py
之后你会看到这个结果
https://github.com/adafruit/Adafruit_CircuitPython_SSD1306之后我们需要开启这个下载这个库
sudo pip3 install adafruit-circuitpython-ssd1306
sudo apt-get install python3-pip
sudo apt-get install python3-pil
就这个驱动库
在最上面我们已经开启了了I2C的功能:

用这个语句来看我们的显示器的地址在哪里
# SPDX-FileCopyrightText: 2017 Tony DiCola for Adafruit Industries# SPDX-FileCopyrightText: 2017 James DeVito for Adafruit Industries# SPDX-License-Identifier: MIT
# This example is for use on (Linux) computers that are using CPython with# Adafruit Blinka to support CircuitPython libraries. CircuitPython does# not support PIL/pillow (python imaging library)!
import timeimport subprocess
from board import SCL, SDAimport busiofrom PIL import Image, ImageDraw, ImageFontimport adafruit_ssd1306
# Create the I2C interface.i2c = busio.I2C(SCL, SDA)
# Create the SSD1306 OLED class.# The first two parameters are the pixel width and pixel height. Change these# to the right size for your display!disp = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c)
# Clear display.disp.fill(0)disp.show()
# Create blank image for drawing.# Make sure to create image with mode '1' for 1-bit color.width = disp.widthheight = disp.heightimage = Image.new("1", (width, height))
# Get drawing object to draw on image.draw = ImageDraw.Draw(image)
# Draw a black filled box to clear the image.draw.rectangle((0, 0, width, height), outline=0, fill=0)
# Draw some shapes.# First define some constants to allow easy resizing of shapes.padding = -2top = paddingbottom = height - padding# Move left to right keeping track of the current x position for drawing shapes.x = 0
# Load default font.font = ImageFont.load_default()
# Alternatively load a TTF font. Make sure the .ttf font file is in the# same directory as the python script!# Some other nice fonts to try: http://www.dafont.com/bitmap.php# font = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', 9)
while True:
# Draw a black filled box to clear the image. draw.rectangle((0, 0, width, height), outline=0, fill=0)
# Shell scripts for system monitoring from here: # https://unix.stackexchange.com/questions/119126/command-to-display-memory-usage-disk-usage-and-cpu-load cmd = "hostname -I | cut -d' ' -f1" IP = subprocess.check_output(cmd, shell=True).decode("utf-8") cmd = "top -bn1 | grep load | awk '{printf \"CPU Load: %.2f\", $(NF-2)}'" CPU = subprocess.check_output(cmd, shell=True).decode("utf-8") cmd = "free -m | awk 'NR==2{printf \"Mem: %s/%s MB %.2f%%\", $3,$2,$3*100/$2 }'" MemUsage = subprocess.check_output(cmd, shell=True).decode("utf-8") cmd = 'df -h | awk \'$NF=="/"{printf "Disk: %d/%d GB %s", $3,$2,$5}\'' Disk = subprocess.check_output(cmd, shell=True).decode("utf-8")
# Write four lines of text.
draw.text((x, top + 0), "IP: " + IP, font=font, fill=255) draw.text((x, top + 8), CPU, font=font, fill=255) draw.text((x, top + 16), MemUsage, font=font, fill=255) draw.text((x, top + 25), Disk, font=font, fill=255)
# Display image. disp.image(image) disp.show() time.sleep(0.1)
这段程序就是把机器内部的运行情况在显示屏上打印
sudo python3 stats.py然后执行这个语句https://github.com/adafruit/Adafruit_CircuitPython_SSD1306/tree/master/examples
还有很多例子,很丰富
我们还想在开机没有屏幕的情况下来运行这个脚本
sudo nano /etc/rc.local然后添加一个
sudo python3 /home/pi/stats.py &
记得最后的exit 0
然后重启
加快显示速度
为了获得最佳性能,尤其是要进行快速动画时,你需要调整 I2C 内核以以 1MHz 的速度运行。默认情况下,它可能为 100KHz 或 400KHz
要进行此编辑,请使用sudo nano /boot/config.txt
并添加到文件的末尾
dtparam=i2c_baudrate=1000000

这样刷新起来就快了

dfrobot给了一个屏幕
http://wiki.dfrobot.com.cn/_SKU_DFR0486_Gravity_I2C_OLED-2864%E6%98%BE%E7%A4%BA%E5%B1%8F
和上文的芯片一样,我就可以重新封装一个Py库来移植我的小屏幕~

这张图在构建我们自己的支架的时候可以参考

对于上面的电机驱动模块是用的I2C控制的
https://drive.google.com/file/d/1tsuSY3iZrfiKu4ww-RX-eCPcwuT2DPwJ/view
如果用这个页面的镜像的话,它是把桌面删除的
这个是需要烧录到一张新的内存卡内部的镜像
sudo nmcli device wifi connect <SSID> password <PASSWORD>这个命令就是来设置WiFi连接的

首先看目前可以用的网络设备

打印可用网络
git clone http://github.com/NVIDIA-AI-IOT/jetbot.git
我们此时克隆这个库

看看里面的东西

然后就是执行里面的脚本

注意是将GUI禁止了

这里打开先

因为不是用的这个镜像,所以没有启动dorker

分别是基本的遥控功能,在浏览器内可以控制

这个也是遥控

避障

巡线

物体追踪
如果上面的Dorker开启有问题,可以试试这样:
第 1 步 - 配置系统
首先,调用脚本配置电源模式和其他参数。scripts/configure_jetson.sh
cd jetbot
./scripts/configure_jetson.sh
接下来,源脚本来配置与 JetBot Docker 相关的各种环境变量。docker/configure.sh
cd docker
source configure.sh
最后,如果尚未,请将默认 Docker 运行时设置为 NVIDIA。这对于将 CUDA 相关组件与容器一起使用是需要的。
./set_nvidia_runtime.sh
如果需要,还可以在 Jupyter 容器上设置内存限制。
export JETBOT_JUPYTER_MEMORY=500m
export JETBOT_JUPYTER_MEMORY_SWAP=3G
第 2 步 - 启用所有容器
调用以下内容以启用 JetBot Docker 容器
sudo systemctl enable docker # enable docker daemon at boot
./enable.sh $HOME # we'll use home directory as working directory, set this as you please.
现在,你可以从网络浏览器转到并开始编程JetBot!你可以在本地网络上的任何计算机上进行此操作。要登录的密码为 。https://<jetbot_ip>:8888jetbot

我还是有错误,可能是我dorker的原因~
这个是小车的构建指南就先说到这里,感兴趣的~我们下期再见!
