




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
《学习任务2:键盘自动驾驶场景设计》控制无人车智能网联创新实验室学习任务2:
键盘控制1.代码讲解2.实际操作3.视频演示《上机实践部分——自动驾驶场景编程》1代码讲解•键盘控制程序使用的是raceworld1场景,
由raceworld1.launch文件启动
。
找到/root/aliyun_demo/src/raceworld/launch文件夹中的raceworld1.launch文件并打开。•在launch文件内加载了多个控制器,
其中left_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:
键盘控制《上机实践部分——自动驾驶场景编程》•在加载控制器代码的下面,
调用了一个名为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
的节点,
订阅并接收/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类型消息后经过适当的转换,
将速度和转向信息发布给之前所述六个控制器。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:
键盘控制《上机实践部分——自动驾驶场景编程》•
然后分别根据按键设置对应的速度以及转角
。
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类型的消息并设置好相应数据后,将其作为/deepracer1/ackermann_c
md_mux/output消息发布,
之后经由servo_comannd1.py中所设置的节点转换后发布给控制器,
以此实
现键盘对小车的控制。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•
当按下对应的按键时,
小车就会开始移动
。
并
且在两个终端中可以看
到消息的发布与接收。•新建另一个终端并输入如图所示命令运行键盘控制程序。学习任务2:
键盘控制《上机实践部分——自动驾驶场景编程》•如果我们查看/deepracer1/left_rear_wheel_velocity_controller/command主题信息的话将会看到发布者是servo_comannds1.py中所创建的servo_comma
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025至2030年中国复方扶芳藤合剂数据监测研究报告
- 河南省安阳市殷都区2024-2025学年九年级上学期1月期末化学试题(含答案)
- 2019-2025年消防设施操作员之消防设备高级技能自我检测试卷A卷附答案
- 2025年消防设施操作员之消防设备高级技能能力检测试卷B卷附答案
- 2023-2024学年广东省广州大学附中七年级(下)期中数学试卷(含答案)
- 新疆题型专练+2024新疆中考
- 部门承包合同(2篇)
- 2025年反洗钱知识竞赛多选题库及答案(共70题)
- 产品手册与功能使用指南汇编
- 三农行业实战指南之土地流转操作流程
- 【翻译知识】新闻标题翻译
- MSDS中文版(锂电池电解液)
- (正式版)YBT 6328-2024 冶金工业建构筑物安全运维技术规范
- 2024年中国煤科煤炭科学技术研究院有限公司招聘笔试参考题库含答案解析
- 线切割操作规程培训
- 光伏安装培训课件模板
- 有机化学(冯骏材编)课后习题答案
- 新法律援助基础知识讲座
- 图文解读中小学教育惩戒规则(试行)全文内容课件模板
- 起重机械安全技术规程(TSG-51-2023)宣贯解读课件
- 《建筑摄影5构》课件
评论
0/150
提交评论