智能網(wǎng)聯(lián)汽車計(jì)算平臺(tái)部署與測(cè)試 課件 學(xué)習(xí)任務(wù)2:鍵盤(pán)控制無(wú)人車_第1頁(yè)
智能網(wǎng)聯(lián)汽車計(jì)算平臺(tái)部署與測(cè)試 課件 學(xué)習(xí)任務(wù)2:鍵盤(pán)控制無(wú)人車_第2頁(yè)
智能網(wǎng)聯(lián)汽車計(jì)算平臺(tái)部署與測(cè)試 課件 學(xué)習(xí)任務(wù)2:鍵盤(pán)控制無(wú)人車_第3頁(yè)
智能網(wǎng)聯(lián)汽車計(jì)算平臺(tái)部署與測(cè)試 課件 學(xué)習(xí)任務(wù)2:鍵盤(pán)控制無(wú)人車_第4頁(yè)
智能網(wǎng)聯(lián)汽車計(jì)算平臺(tái)部署與測(cè)試 課件 學(xué)習(xí)任務(wù)2:鍵盤(pán)控制無(wú)人車_第5頁(yè)
已閱讀5頁(yè),還剩7頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

《學(xué)習(xí)任務(wù)2:鍵盤(pán)自動(dòng)駕駛場(chǎng)景設(shè)計(jì)》控制無(wú)人車智能網(wǎng)聯(lián)創(chuàng)新實(shí)驗(yàn)室學(xué)習(xí)任務(wù)2:

鍵盤(pán)控制1.代碼講解2.實(shí)際操作3.視頻演示《上機(jī)實(shí)踐部分——自動(dòng)駕駛場(chǎng)景編程》1代碼講解?鍵盤(pán)控制程序使用的是raceworld1場(chǎng)景,

由raceworld1.launch文件啟動(dòng)

。

找到/root/aliyun_demo/src/raceworld/launch文件夾中的raceworld1.launch文件并打開(kāi)。?在launch文件內(nèi)加載了多個(gè)控制器,

其中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消息,

分別控制了左右后輪速度,

左右前輪速度和轉(zhuǎn)向

角度。<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"/>學(xué)習(xí)任務(wù)2:

鍵盤(pán)控制《上機(jī)實(shí)踐部分——自動(dòng)駕駛場(chǎng)景編程》?在加載控制器代碼的下面,

調(diào)用了一個(gè)名為servo_comannds1.py的代碼文件。<node

p

kg="raceworld"type="servo_commands1.py"name="servo_commands"output="screen">?打開(kāi)/root/aliyun_demo/src/raceworld/scripts文件夾中的servo_comannds1.py文件我們可以看到,

代碼中新建了一

個(gè)名為servo_comannds

的節(jié)點(diǎn),

訂閱并接收/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()學(xué)習(xí)任務(wù)2:

鍵盤(pán)控制《上機(jī)實(shí)踐部分——自動(dòng)駕駛場(chǎng)景編程》?在接收到AckermannDriveStamped類型消息后經(jīng)過(guò)適當(dāng)?shù)霓D(zhuǎn)換,

將速度和轉(zhuǎn)向信息發(fā)布給之前所述六個(gè)控制器。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")學(xué)習(xí)任務(wù)2:

鍵盤(pán)控制《上機(jī)實(shí)踐部分——自動(dòng)駕駛場(chǎng)景編程》?啟動(dòng)鍵盤(pán)控制程序需要運(yùn)行/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()學(xué)習(xí)任務(wù)2:

鍵盤(pán)控制《上機(jī)實(shí)踐部分——自動(dòng)駕駛場(chǎng)景編程》?

然后分別根據(jù)按鍵設(shè)置對(duì)應(yīng)的速度以及轉(zhuǎn)角

。

W為前進(jìn),

S為后退,

A為左前進(jìn),

D為右前進(jìn),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學(xué)習(xí)任務(wù)2:

鍵盤(pán)控制《上機(jī)實(shí)踐部分——自動(dòng)駕駛場(chǎng)景編程》?新建一個(gè)AckermannDriveStamped類型的消息并設(shè)置好相應(yīng)數(shù)據(jù)后,將其作為/deepracer1/ackermann_c

md_mux/output消息發(fā)布,

之后經(jīng)由servo_comannd1.py中所設(shè)置的節(jié)點(diǎn)轉(zhuǎn)換后發(fā)布給控制器,

以此實(shí)

現(xiàn)鍵盤(pán)對(duì)小車的控制。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")學(xué)習(xí)任務(wù)2:

鍵盤(pán)控制《上機(jī)實(shí)踐部分——自動(dòng)駕駛場(chǎng)景編程》2實(shí)際操作?打開(kāi)終端,

輸入如圖所示命令開(kāi)啟raceworld1

Gazebo場(chǎng)景

。

如右圖所示。cdaliyun_demosourcedevel/setup.bashroslaunchraceworldraceworld1.launch學(xué)習(xí)任務(wù)2:

鍵盤(pán)控制《上機(jī)實(shí)踐部分——自動(dòng)駕駛場(chǎng)景編程》cdaliyun_demosourcedevel/setup.bashrosrunraceworldkey_op.py?

當(dāng)按下對(duì)應(yīng)的按鍵時(shí),

小車就會(huì)開(kāi)始移動(dòng)

且在兩個(gè)終端中可以看

到消息的發(fā)布與接收。?新建另一個(gè)終端并輸入如圖所示命令運(yùn)行鍵盤(pán)控制程序。學(xué)習(xí)任務(wù)2:

鍵盤(pán)控制《上機(jī)實(shí)踐部分——自動(dòng)駕駛場(chǎng)景編程》?如果我們查看/deepracer1/left_rear_wheel_velocity_controller/command主題信息的話將會(huì)看到發(fā)布者是servo_comannds1.py中所創(chuàng)建的servo_comma

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論