




版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領
文檔簡介
《學習任務2:鍵盤自動駕駛場景設計》控制無人車智能網(wǎng)聯(lián)創(chuàng)新實驗室學習任務2:
鍵盤控制1.代碼講解2.實際操作3.視頻演示《上機實踐部分——自動駕駛場景編程》1代碼講解?鍵盤控制程序使用的是raceworld1場景,
由raceworld1.launch文件啟動
。
找到/root/aliyun_demo/src/raceworld/launch文件夾中的raceworld1.launch文件并打開。?在launch文件內(nèi)加載了多個控制器,
其中l(wèi)eft_rear_wheel_velocity_controller,
right_rear_wheel_velocity_controller,left_front_wheel_velocity_controller,
right_front_wheel_velocity_controller,left_steering_hinge_position_controller和right_steering_hinge_position_controller接收ROS消息,
分別控制了左右后輪速度,
左右前輪速度和轉向
角度。<node
name="controller_manager"p
kg="controller_manager"type="spawner"respawn="false"output="screen"args="left_rear_wheel_velocity_controllerlerleft_front_wheel_velocity_controllerllerleft_steering_hinge_position_controllerright_rear_wheel_velocity_controlright_front_wheel_velocity_controright_steering_hinge_position_controllerjoint_state_controller"/>學習任務2:
鍵盤控制《上機實踐部分——自動駕駛場景編程》?在加載控制器代碼的下面,
調(diào)用了一個名為servo_comannds1.py的代碼文件。<node
p
kg="raceworld"type="servo_commands1.py"name="servo_commands"output="screen">?打開/root/aliyun_demo/src/raceworld/scripts文件夾中的servo_comannds1.py文件我們可以看到,
代碼中新建了一
個名為servo_comannds
的節(jié)點,
訂閱并接收/deepracer1/ackermann_cmd_mux/output消息。def
servo_commands():globalflag_moverospy.in
it_node(
'servo_commands
',anonymous=True)rospy.Subscriber("/deepracer1/ackermann_cmd_mux/output",AckermannDriveStamped,set_throttle_steer)rospy.spin()學習任務2:
鍵盤控制《上機實踐部分——自動駕駛場景編程》?在接收到AckermannDriveStamped類型消息后經(jīng)過適當?shù)霓D換,
將速度和轉向信息發(fā)布給之前所述六個控制器。def
set_throttle_steer(data):globalflag_movepub_vel_left_rear_wheel=rospy.Publisher("/deepracer1/left_rear_wheel_velocity_controller/command",Float64,queue_size=1)pub_vel_right_rear_wheel=rospy.Publisher("/deepracer1/right_rear_wheel_velocity_controller/command",Float64,queue_size=1)pub_vel_left_front_wheel=rospy.Publisher("/deepracer1/left_front_wheel_velocity_controller/command",Float64,queue_size=1)pub_vel_right_front_wheel=rospy.Publisher("/deepracer1/right_front_wheel_velocity_controller/command",Float64,queue_size=1)pub_pos_left_steering_hinge=rospy.Publisher("/deepracer1/left_steering_hinge_position_controller/command",Float64,queue_size=1)pub_pos_right_steering_hinge=rospy.Publisher("/deepracer1/right_steering_hinge_position_controller/command",Float64,queue_size=1)throttle=data.drive.speed*28print("Throttle:",throttle)steer=data.drive.steering_angleprint("Steer:",steer)pub_vel_left_rear_wheel.publish(throttle)pub_vel_right_rear_wheel.publish(throttle)pub_vel_left_front_wheel.publish(throttle)pub_vel_right_front_wheel.publish(throttle)pub_pos_left_steering_hinge.publish(steer)pub_pos_right_steering_hinge.publish(steer)print("MessageFromservo_commands1.py
Published\n")學習任務2:
鍵盤控制《上機實踐部分——自動駕駛場景編程》?啟動鍵盤控制程序需要運行/root/aliyun_demo/src/raceworld/scripts文件夾中的key_op.py文件。?首先需要獲取按鍵輸入。def
getKey():tty.setraw(sys.stdin.fileno())select.select([sys.stdin],
[],
[],0)key=
sys.stdin.read(1)termios.tcsetattr(sys.stdin,termios.TCSADRAIN,settings)return
keysettings=termios.tcgetattr(sys.stdin)def
pub_cmd():index
=
1rospy.in
it_node("pub_cmd")pub=rospy.Publisher("/deepracer"+str(index)+"/ackermann_cmd_mux/output",AckermannDriveStamped,queue_size=10)a
km=AckermannDriveStamped()while
1:x=0a=0key
=getKey()學習任務2:
鍵盤控制《上機實踐部分——自動駕駛場景編程》?
然后分別根據(jù)按鍵設置對應的速度以及轉角
。
W為前進,
S為后退,
A為左前進,
D為右前進,X為停止行駛,
O為退出
程序。if
key
==
'w
':x=0.3a=0elif
key
==
's
':x=-0.3a=0elif
key
==
'a
':x=0.3a=2elif
key
==
'd
':x=0.3a=-0.7elif
key
==
'x
':x=0a=0elif
key
==
'o
':breakelse:continue學習任務2:
鍵盤控制《上機實踐部分——自動駕駛場景編程》?新建一個AckermannDriveStamped類型的消息并設置好相應數(shù)據(jù)后,將其作為/deepracer1/ackermann_c
md_mux/output消息發(fā)布,
之后經(jīng)由servo_comannd1.py中所設置的節(jié)點轉換后發(fā)布給控制器,
以此實
現(xiàn)鍵盤對小車的控制。a
km.drive.speed=
xprint("Speed:",akm.drive.speed)a
km.drive.steering_angle=
aprint("Steering_Angle:",akm.drive.steering_angle)pub.publish(a
km)print("MessageFromkey_op.py
Published\n")學習任務2:
鍵盤控制《上機實踐部分——自動駕駛場景編程》2實際操作?打開終端,
輸入如圖所示命令開啟raceworld1
Gazebo場景
。
如右圖所示。cdaliyun_demosourcedevel/setup.bashroslaunchraceworldraceworld1.launch學習任務2:
鍵盤控制《上機實踐部分——自動駕駛場景編程》cdaliyun_demosourcedevel/setup.bashrosrunraceworldkey_op.py?
當按下對應的按鍵時,
小車就會開始移動
。
并
且在兩個終端中可以看
到消息的發(fā)布與接收。?新建另一個終端并輸入如圖所示命令運行鍵盤控制程序。學習任務2:
鍵盤控制《上機實踐部分——自動駕駛場景編程》?如果我們查看/deepracer1/left_rear_wheel_velocity_controller/command主題信息的話將會看到發(fā)布者是servo_comannds1.py中所創(chuàng)建的servo_comma
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 金融科技助推銀行網(wǎng)點數(shù)字化轉型策略
- 香蕉購銷合同協(xié)議書范本
- 砂石出售合同協(xié)議書范本
- 2025秋五年級上冊語文(統(tǒng)編版)-【27 我的長生果】作業(yè)課件
- 煤炭產(chǎn)品買賣合同協(xié)議書
- 健身房協(xié)議書合同
- 購房合同轉賣協(xié)議書范本
- 成都智能電表項目商業(yè)計劃書模板范文
- 擬定合同簽約協(xié)議書怎么寫
- 鉛酸蓄電池公司綠色建筑方案分析(范文)
- 店面出讓股權協(xié)議書
- 深圳2025年深圳市住房公積金管理中心員額人員招聘8人筆試歷年參考題庫附帶答案詳解
- 英文電影鑒賞知到智慧樹期末考試答案題庫2025年北華大學
- 超標準洪水應急預案
- 美容診所合作協(xié)議書
- 2025湖南中考:英語必背知識點
- 2025年人教版小學一年級下學期奧林匹克數(shù)學競賽試卷(附答案解析)
- 2025年滁州市軌道交通運營有限公司第二批次招聘31人筆試參考題庫附帶答案詳解
- 2025年高考英語考前熱點話題押題卷(新高考Ⅰ卷)-2025年高考英語模擬考試(解析版)
- 浙江國企筆試題目及答案
- 2025年內(nèi)蒙古自治區(qū)呼和浩特市中考二模英語試題 (含答案無聽力音頻及原文)
評論
0/150
提交評論