




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
《学习任务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年山东省东营市中考招生考试数学真题试卷
- 预防跌倒护理课件
- 2024年民族宗教政策法规宣传月知识竞赛考试题库(含答案)
- 《3-6岁儿童学习与发展指南》考试参考题库120题(含答案)
- 诊所中药饮片清单
- 零信任安全架构-第1篇
- 《发酵饲料的应用》课件
- 物业客服主管的角色与职责解析
- 国家开放大学2023年7月期末统一试《22417客户关系管理》试题及答案-开放专科
- 西式面点师(高级)课件 项目4 甜品制作
- 鼎捷T100-V1.0-销售管理用户手册-简体
- 抗生素的合理应用-专业知识讲座培训课件
- 港式清单模板
评论
0/150
提交评论