版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
《学习任务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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026考研数学二历年真题|考前押题卷
- 【2024考研】全国统考数学二冲刺试卷(提分冲刺卷)
- 2026数学一期中试卷(命题趋势分析)
- 护士血压考试题及答案
- 2026年高职应用化工(化学分析)试题及答案
- 铁路限界考试题及答案
- 2026年高职建筑数字化技术(BIM应用)试题及答案
- 调研会议考试题及答案
- 2025年天津市医药流通企业恒温仓库新建可行性研究报告
- 10万吨花椒籽加工项目可行性研究报告
- 麻醉病人的并发症处理与护理
- 曼巴精神:科比自传的核心启示
- 肩颈专业知识话术
- (新教材)2026年人教版二年级上册数学 第2课时 分类与整 理(2) 课件
- 诗经中的陇东古方国课件
- 2025安徽国控集团所属企业招聘1人参考笔试题库及答案解析
- 2025四川绵阳市绵投置地有限公司招聘成本管理岗位拟录用人员笔试历年典型考点题库附带答案详解2套试卷
- 楼长寝室长培训
- 精神科用药错误应急措施
- 东莞理工学院2024年电子信息工程(通信)通信工程伦理试题及答案
- 模拟政协课件
评论
0/150
提交评论