【得捷电子Follow me第1期】+基于Pico-w高精度GNSS定位巡检机器人开发
[复制链接]
1,视频介绍;
2.项目总结报告
Raspberry Pico W Pico W树莓派开发板是使用基于RP2040芯片的MCU开发板,用双核Arm Cortex-M0+@133Mhz,芯片内置264KB SRAM 和2MB的板载内存,含有26个多功能GPIO引脚。支持U2的USB大容量存储启动模式,用于拖放式编程,并支持MicroPython/C/C++。被设计为RP2040的一个低成本但灵活的开发平台,具有2.4GHz无线接口和以下关键功能:
•带2MB闪存的RP2040微控制器
•车载单频段2.4GHz无线接口(802.11n)
•Micro USB B端口,用于电源和数据(以及重新编程闪存)
•2×UART、2×I2C、2×SPI、16×PWM通道
• 23个GPIO仅为数字,其中三个也支持ADC。
• 高质量、低成本、高可用性
开发板自带Air530GNSS模组:高精度全球导航卫星系统(GNSS)技术。实时动态(RTK)GNSS接收机可实现厘米级定位精度,系统而有效地指引室外机器人载体通过自身携带的传感器在完全陌生的环境下通过感知到的信息估计自身的运动并实时的构建周围环境地图,为进一步的避障和路径规划等任务奠定基础,其功能部件主要由以下部分组成:
GNSS作为户外自主定位的主要技术手段,可以通过差分技术、精密单点定位技术等手段,实时达到亚米级、分米级和厘米级不同精度定位,可直接用于室外机器人定位判断。对于定位方式,目前主要用的是实时动态RTK,其水平精度可达±8mm+1ppm,高程精度可达±15mm+1ppm。RTK基站与移动站之间的数传只需要保证基站数据传输到移动站,无需回传给基站,对于通讯设计上十分简便。
开发板再带WiFi模块。使用WiFi的优势在于不用接入互联网,所有机器人部署在局域网内,数据保密性强,搭配大功率WiFi基站传输半径可达400米左右,适合园区内巡检、安防等应用场景,经济型十分可观。
历史开发记录;
1),【得捷电子Follow me第1期】篇一:熟悉Pico W开发板,thonny软件与micropython基础
https://bbs.eeworld.com.cn/thread-1247204-1-1.html
2 )【得捷电子Follow me第1期】篇2 :驱动驱动LED测试
https://bbs.eeworld.com.cn/thread-1247207-1-1.html
3 【得捷电子Follow me第1期】篇3 -通过Pi Pico W板载WiFi模块通过网络同步系统时间
https://bbs.eeworld.com.cn/thread-1247445-1-1.html
4 【得捷电子Follow me第1期】篇4 -通过Pi Pico W驱动Air530 模块定位
https://bbs.eeworld.com.cn/thread-1247460-1-1.html
项目实现:
对本活动的心得体会:得捷电子Follow me活动非常好,项目由于海关等因素开发时间还是比较仓促的。对于Pico W Pico W强大的
代码:PWM:
from pyb import Pin, Timer
#伸缩杆
rod_P1 = Pin('X9', Pin.OUT_PP)
rod_P2 = Pin('X10', Pin.OUT_PP)
#伸缩杆(rod)对应定时器
tim_rod = Timer(4, freq=100) #要实现每秒0.1ms量级
rod_go = tim_rod.channel(1, Timer.PWM, pin=rod_P1)
rod_back = tim_rod.channel(2, Timer.PWM, pin=rod_P2)
while True:
#前进
rod_go.pulse_width_percent(100) # =Pin.high()
rod_back.pulse_width_percent(0) # =Pin.low()
pyb.delay(1000) #调时间就是调距离
#后退
rod_go.pulse_width_percent(0)
rod_back.pulse_width_percent(100)
pyb.delay(1000) #调时间就是调距离
from pyb import Pin, Timer
#左轮
left1 = Pin('X9', Pin.OUT_PP)
left2 = Pin('X10', Pin.OUT_PP)
#左轮对应定时器
tim_left = Timer(4, freq=100) #要实现每个脉冲持续10ms
left_go = tim_left.channel(1, Timer.PWM, pin=left1)
left_stop = tim_left.channel(2, Timer.PWM, pin=left2)
#右轮
right1 = Pin('Y7', Pin.OUT_PP)
right2 = Pin('Y8', Pin.OUT_PP)
#左轮对应定时器
tim_right = Timer(1, freq=100) #要实现每个脉冲持续10ms
right_go = tim_left.channel(2, Timer.PWM, pin=right1)
right_stop = tim_left.channel(3, Timer.PWM, pin=right2)
while True:
#左轮,可PWM调速
left_go.pulse_width_percent(100) #0-100进行调速,100为全速,0为停止
left_stop.pulse_width_percent(0) #默认为0,作为调速基准
#右轮,可PWM调速
right_go.pulse_width_percent(100) #0-100进行调速,100为全速,0为停止
right_stop.pulse_width_percent(0) #默认为0,作为调速基准
ADC 采集NTC 温度
import machine
import utime
sensor_temp = machine.ADC(4)
conversion_factor = 3.3 / (65535)
while True:
reading = sensor_temp.read_u16() * conversion_factor
temperature = 27 - (reading - 0.706)/0.001721
print(temperature)
utime.sleep(2)
蜂鸣器
import machine
sensor_pir = machine.Pin(28, machine.Pin.IN)
def pir_handler(pin):
print("ALARM! Motion detected!")
sensor_pir.irq(trigger=machine.Pin.IRQ_RISING, handler=pir_handler)
RTC
import network
import socket
ssid = '华莱士'
password = '4008053166'
nic = network.WLAN(network.STA_IF)
nic.active(True) #使能WLAN模块
nic.connect(ssid,password) #连接wifi
while nic.isconnected() != True: #判断是否连接成功
print('.')
time.sleep(1)
print(nic.ifconfig()) #输出ip地址
import ntptime
ntptime.host = "ntp.aliyun.com" #修改ntp服务器地址
ntptime.timeout = 3
#修改超时时间
sec = ntptime.time() #获取时间
print(sec)
import utime
print(utime.localtime(sec+8*3600))#转换为北京时间
电机驱动
from pyb import Pin, Timer
import pyb
#p_A用于输出PWM脉冲
p_A = Pin('X1')
tim1 = pyb.Timer(2, freq=1600) #定时器2设定频率为1600,即每秒输出1600个脉冲数,单位时间内的脉冲数越大,步进电机的速度越快
ch1 = tim1.channel(1, Timer.PWM, pin=p_A) #设定为PWM模式
#设定控制方向的引脚,
dir_ahead = Pin('X4', Pin.OUT_PP)
dir_back = Pin('X6', Pin.OUT_PP)
# while 1:
#向前,方向+高电平。方向-低电平
dir_ahead.high()
dir_back.low()
ch1.pulse_width_percent(50) #输出占空比为50%的PWM脉冲,即在一个脉冲中,高电平脉冲一半时间,低电平脉冲一半时间
pyb.delay(1000)
#向后,相反
dir_back.high()
dir_ahead.low()
ch1.pulse_width_percent(50)
pyb.delay(1000)
dir_ahead.low()
dir_back.low()
Modbus协议;
import modbus_tk.modbus_tcp as mt
import modbus_tk.defines as md
# 远程连接到服务器端
master = mt.TcpMaster("192.168.1.10", 502)
master.set_timeout(5.0)
# @slave=1 : identifier of the slave. from 1 to 247. 0为广播所有的slave
# @function_code=READ_HOLDING_REGISTERS:功能码
# @starting_address=1:开始地址
# @quantity_of_x=3:寄存器/线圈的数量
# @output_value:一个整数或可迭代的值:1/[1,1,1,0,0,1]/xrange(12)
# @data_format
# @expected_length
Hold_value = master.execute(slave=1, function_code=md.READ_HOLDING_REGISTERS, starting_address=1, quantity_of_x=3, output_value=5)
Hold_value = master.execute(slave=1, function_code=md.READ_HOLDING_REGISTERS, starting_address=1, quantity_of_x=3, output_value=5)
Coils_value = master.execute(slave=1, function_code=md.READ_COILS, starting_address=1, quantity_of_x=3, output_value=5)
print(Hold_value) # 取到的寄存器的值格式为元组(55, 12, 44)
print(Hold_value) # 取到的寄存器的值格式为元组(1, 1, 1)
|