1. 功能描述
本文提供的示例所實(shí)現(xiàn)的功能為:用手機(jī)APP遙控斜三角履帶底盤樣機(jī)實(shí)現(xiàn)移動(dòng),包括前進(jìn)、停止、后退、原地左轉(zhuǎn)、原地右轉(zhuǎn)。
2. 電子硬件
在這個(gè)示例中,采用了以下硬件,請大家參考:
Basra主控板(兼容Arduino Uno)、Bigfish2.1擴(kuò)展板、7.4V鋰電池、藍(lán)牙串口模塊
為斜三角履帶底盤樣機(jī)安裝藍(lán)牙串口模塊,斜三角履帶底盤樣機(jī)有兩種擺放方式:
車身右側(cè)為安裝了藍(lán)牙串口模塊的主控板,左側(cè)控制板請忽略
3. 示例程序
編程環(huán)境:Arduino 1.8.19
程序通過使用if語句來判斷讀取到的串口的不同字符值來匹配不同的動(dòng)作,從而實(shí)現(xiàn)對機(jī)器人的遠(yuǎn)程控制。
接收到“1”的時(shí)候,執(zhí)行前進(jìn);
接收到“2”的時(shí)候,執(zhí)行后退;
接收到“3”的時(shí)候,執(zhí)行左轉(zhuǎn);
接收到“4”的時(shí)候,執(zhí)行右轉(zhuǎn);
接收到“5”的時(shí)候,執(zhí)行停止;
手機(jī)APP的鍵值按上述規(guī)則進(jìn)行配置,然后單片機(jī)接收到不同的信息,對應(yīng)執(zhí)行不同的動(dòng)作。
例程代碼(robot_ble_control.ino)如下:
/*------------------------------------------------------------------------------------ 版權(quán)說明:Copyright 2022 Robottime(Beijing) Technology Co., Ltd. All Rights Reserved. Distributed under MIT license.See file LICENSE for detail or copy at https://opensource.org/licenses/MIT by 機(jī)器譜 2022-9-28 https://www.robotway.com/ ------------------------------ 實(shí)功能: 從串口(藍(lán)牙)接收字符,根據(jù)不同字符分別做出前進(jìn)、后退、停止、原地左轉(zhuǎn)、原地右轉(zhuǎn)的動(dòng)作。 ----------------------------------------------------- 實(shí)驗(yàn)接線: 左輪:D9,D10 右輪:D5,D6。 ------------------------------------------------------------------------------------*/ int _ABVAR_1_Bluetooth_data = 0 ; void Left(); void Stop(); void Right(); void Back(); void Forward(); void setup() { Serial.begin(9600); pinMode( 5 , OUTPUT); pinMode( 6 , OUTPUT); pinMode( 9 , OUTPUT); pinMode( 10 , OUTPUT); } void loop() { _ABVAR_1_Bluetooth_data = Serial.parseInt() ; if (( ( _ABVAR_1_Bluetooth_data ) > ( 0 ) )) { if (( ( _ABVAR_1_Bluetooth_data ) == ( 1 ) )) { Forward(); } if (( ( _ABVAR_1_Bluetooth_data ) == ( 2 ) )) { Back(); } if (( ( _ABVAR_1_Bluetooth_data ) == ( 3 ) )) { Left(); } if (( ( _ABVAR_1_Bluetooth_data ) == ( 4 ) )) { Right(); } if (( ( _ABVAR_1_Bluetooth_data ) == ( 5 ) )) { Stop(); } } } void Right() { digitalWrite( 5 , HIGH ); digitalWrite( 6 , LOW ); digitalWrite( 9 , LOW ); digitalWrite( 10 , HIGH ); } void Back() { digitalWrite( 5 , HIGH ); digitalWrite( 6 , LOW ); digitalWrite( 9 , HIGH ); digitalWrite( 10 , LOW ); } void Left() { digitalWrite( 5 , LOW ); digitalWrite( 6 , HIGH ); digitalWrite( 9 , HIGH ); digitalWrite( 10 , LOW ); } void Forward() { digitalWrite( 5 , LOW ); digitalWrite( 6 , HIGH ); digitalWrite( 9 , LOW ); digitalWrite( 10 , HIGH ); } void Stop() { digitalWrite( 5 , HIGH ); digitalWrite( 6 , HIGH ); digitalWrite( 9 , HIGH ); digitalWrite( 10 , HIGH ); } |
審核編輯 黃昊宇
-
機(jī)器人
+關(guān)注
關(guān)注
211文章
28632瀏覽量
208278 -
藍(lán)牙
+關(guān)注
關(guān)注
114文章
5866瀏覽量
171130
發(fā)布評論請先 登錄
相關(guān)推薦
評論