> ~/.bashrcsource ~/.bashrc这下准备就完成了,可以启动launc文件了。roslaunch racecar_gazebo racecar.lau_mit racecar gazebo">
赞
踩
首先先准备我们的开源仿真包mit-racecar,博主已经把资源上传到CSDN上了。需要请自取。
https://download.csdn.net/download/weixin_44606638/12470588
接下来将racecar_gazebo放入工作区间
编译工作区间
catkin_make
设置环境变量
echo "source ~/catkin_ws/devel/setup.bash" >> ~/.bashrc
source ~/.bashrc
这下准备就完成了,可以启动launc文件了。
roslaunch racecar_gazebo racecar.launch
注意,如果出现raise ResourceNotFound(name, ros_paths=self._ros_paths)
ResourceNotFound: racecar说明你没有racecar的模型
还是老样子,博主博主已经把资源上传到CSDN上了。需要请自取。
https://download.csdn.net/download/weixin_44606638/12470596
如果你执行成功,就会启动gazebo,就可以看见小车模型了。
目前比赛规则已经渐渐明朗,参考官方,制作标准比赛仿真环境,学习阿克曼小车控制,ROS基础和相关智能车算法(后续会补充)。开启Building Editor,依据下图绘制环境:
这时,我们在gazebo中按Ctrl+B,就会弹出绘图画面。
选择Wall,在白色区域画出你需要的赛道模型。
保存并应用:
效果展示:
当然,如果你还要添加障碍物之类的,可以在Insert中自行选择添加。这里我就不多添加了。
新建文件racecar.py
Python代码:
#!/usr/bin/env python """ template_node.py LCHS RACECAR 2016-17 Written by Braden Oh This program serves as a template for a working node. It contains a useful implementation of the drive function, an outline for the main function, and contains all commands necessary to initialize a node. It also contains comments outlining specific documentation. """ #---------------------------------------------------------- # IMPORTS #---------------------------------------------------------- import rospy # Import ROS libraries from sensor_msgs.msg import LaserScan # Import required msg types from ackermann_msgs.msg import AckermannDriveStamped # Other imports here... #---------------------------------------------------------- # CONSTANTS #---------------------------------------------------------- DATA_IN = '/scan' # Read data from this topic DATA_OUT = 'vesc/ackermann_cmd_mux/input/navigation' # Publish data to this topic NODE_NAME = 'sampleController' # Name of the node SPEED = 1.0 # Default speed in m/s # Other constants here... #---------------------------------------------------------- # Functions #---------------------------------------------------------- def drive(speed, angle, myPublisher): msg = AckermannDriveStamped() # Initializes msg object msg.drive.speed = speed # Sets msg speed to entered speed msg.drive.acceleration = 0 # Sets msg acceleration to 0 msg.drive.jerk = 1 # Sets msg jerk to 1 msg.drive.steering_angle = angle # Sets msg steering angle to entered angle msg.drive.steering_angle_velocity = 1 # Sets msg angle velocity to 1 myPublisher.publish(msg) # Publishes the message # def myFunction(parameter_1, parameter_n): # Other functions here #============================ # MAIN #============================ def main(msg): # Initialize publisher object myPublisher = rospy.Publisher(DATA_OUT,AckermannDriveStamped,queue_size=10) # Useful calculations here... # Use the publisher # i.e. to drive straight ahead, call the drive function: # drive(SPEED, 0, myPublisher) #============================ rospy.init_node(NODE_NAME) # Initialize node with preset name rospy.Subscriber(DATA_IN,LaserScan,main) # Create subscriber object # - Reads data from preset topic # - Data of type LaserScan # - Upon new data, execute main rospy.spin() # Continue running until user stops this node
赋予可执行文件:
chmod 777 *
执行脚本:
python racecar.py
结果显示:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。