有没有做网站的团队,关于网站建设费用的报告,个人简历在线制作,江西中企动力做的网站ROS 自动驾驶多点巡航#xff1a;
1、首先创建工作空间#xff1a;
基于我们的artca_ws#xff1b;
2、创建功能包#xff1a;
进入src目录#xff0c;输入命令:
catkin_create_pkg point_pkg std_msgs rospy roscpptest_pkg 为功能包名#xff0c;后面两个是依赖
1、首先创建工作空间
基于我们的artca_ws
2、创建功能包
进入src目录输入命令:
catkin_create_pkg point_pkg std_msgs rospy roscpptest_pkg 为功能包名后面两个是依赖
3、创建python文件
我们通过vscode打开src下功能包 创建 point.py 代码内容写入 :
#!/usr/bin/env python
import rospy
import actionlib
import collections
from actionlib_msgs.msg import *
from geometry_msgs.msg import Pose, PoseWithCovarianceStamped, Point, Quaternion, Twist
from move_base_msgs.msg import MoveBaseAction, MoveBaseGoal
from random import sample
from math import pow, sqrt class MultiNav(): def __init__(self): rospy.init_node(MultiNav, anonymousTrue) rospy.on_shutdown(self.shutdown) # How long in seconds should the robot pause at each location? self.rest_time rospy.get_param(~rest_time, 10) # Are we running in the fake simulator? self.fake_test rospy.get_param(~fake_test, False) # Goal state return values goal_states [PENDING, ACTIVE, PREEMPTED,SUCCEEDED, ABORTED, REJECTED,PREEMPTING, RECALLING, RECALLED,LOST] # Set up the goal locations. Poses are defined in the map frame. # An easy way to find the pose coordinates is to point-and-click # Nav Goals in RViz when running in the simulator. # Pose coordinates are then displayed in the terminal # that was used to launch RViz. locations collections.OrderedDict() locations[point-1] Pose(Point(5.21, -2.07, 0.00), Quaternion(0.000, 0.000, -0.69, 0.72)) locations[point-2] Pose(Point(3.50, -5.78, 0.00), Quaternion(0.000, 0.000, 0.99, 0.021))#locations[point-3] Pose(Point(-6.95, 2.26, 0.00), Quaternion(0.000, 0.000, 0.000, 1.000))#locations[point-4] Pose(Point(-6.50, 2.04, 0.00), Quaternion(0.000, 0.000, 0.000, 1.000))# Publisher to manually control the robot (e.g. to stop it) self.cmd_vel_pub rospy.Publisher(cmd_vel, Twist, queue_size5) # Subscribe to the move_base action server self.move_base actionlib.SimpleActionClient(move_base, MoveBaseAction) rospy.loginfo(Waiting for move_base action server...) # Wait 60 seconds for the action server to become available self.move_base.wait_for_server(rospy.Duration(10)) rospy.loginfo(Connected to move base server) # A variable to hold the initial pose of the robot to be set by the user in RViz initial_pose PoseWithCovarianceStamped() # Variables to keep track of success rate, running time, and distance traveled n_locations len(locations) n_goals 0 n_successes 0 i 0 distance_traveled 0 start_time rospy.Time.now() running_time 0 location last_location # Get the initial pose from the user rospy.loginfo(Click on the map in RViz to set the intial pose...) rospy.wait_for_message(initialpose, PoseWithCovarianceStamped) self.last_location Pose() rospy.Subscriber(initialpose, PoseWithCovarianceStamped, self.update_initial_pose) keyinput int(input(Input 0 to continue,or reget the initialpose!\n))while keyinput ! 0:rospy.loginfo(Click on the map in RViz to set the intial pose...) rospy.wait_for_message(initialpose, PoseWithCovarianceStamped) rospy.Subscriber(initialpose, PoseWithCovarianceStamped, self.update_initial_pose) rospy.loginfo(Press y to continue,or reget the initialpose!)keyinput int(input(Input 0 to continue,or reget the initialpose!))# Make sure we have the initial pose while initial_pose.header.stamp : rospy.sleep(1) rospy.loginfo(Starting navigation test) # Begin the main loop and run through a sequence of locations for location in locations.keys(): rospy.loginfo(Updating current pose.) distance sqrt(pow(locations[location].position.x - initial_pose.pose.pose.position.x, 2) pow(locations[location].position.y - initial_pose.pose.pose.position.y, 2)) initial_pose.header.stamp # Store the last location for distance calculations last_location location # Increment the counters i 1 n_goals 1 # Set up the next goal location self.goal MoveBaseGoal() self.goal.target_pose.pose locations[location] self.goal.target_pose.header.frame_id map self.goal.target_pose.header.stamp rospy.Time.now() # Let the user know where the robot is going next rospy.loginfo(Going to: str(location)) # Start the robot toward the next location self.move_base.send_goal(self.goal) # Allow 5 minutes to get there finished_within_time self.move_base.wait_for_result(rospy.Duration(300)) # Check for success or failure if not finished_within_time: self.move_base.cancel_goal() rospy.loginfo(Timed out achieving goal) else: state self.move_base.get_state() if state GoalStatus.SUCCEEDED: rospy.loginfo(Goal succeeded!) n_successes 1 distance_traveled distance else: rospy.loginfo(Goal failed with error code: str(goal_states[state])) # How long have we been running? running_time rospy.Time.now() - start_time running_time running_time.secs / 60.0 # Print a summary success/failure, distance traveled and time elapsed rospy.loginfo(Success so far: str(n_successes) / str(n_goals) str(100 * n_successes/n_goals) %) rospy.loginfo(Running time: str(trunc(running_time, 1)) min Distance: str(trunc(distance_traveled, 1)) m) rospy.sleep(self.rest_time) def update_initial_pose(self, initial_pose): self.initial_pose initial_pose def shutdown(self): rospy.loginfo(Stopping the robot...) self.move_base.cancel_goal() rospy.sleep(2) self.cmd_vel_pub.publish(Twist()) rospy.sleep(1)
def trunc(f, n): # Truncates/pads a float f to n decimal places without rounding slen len(%.*f % (n, f)) return float(str(f)[:slen]) if __name__ __main__: try: MultiNav() rospy.spin() except rospy.ROSInterruptException: rospy.loginfo(AMCL navigation test finished.)
4、编译
nanonano-desktop:~/artcar_ws/src$ cd ..
nanonano-desktop:~/artcar_ws$ catkin build 5、案例实操
启动小车并进入到相应环境
1打开终端启动底盘环境输入如下命令
$ roslaunch artcar_nav artcar_bringup.launch
2启动导航程序
$ roslaunch artcar_nav artcar_move_base.launch
3启动RVIZ
4获取点位 rostopic echo /move_base_sile/goal 获取点位
roscarroscar-virtual-machine:~/artcar_simulation/src$ rostopic echo /move_base_simple/goal
WARNING: no messages received and simulated time is active.
Is /clock being published?
header: seq: 0stamp: secs: 405nsecs: 141000000frame_id: odom
pose: position: x: 5.21420097351y: -2.07076597214z: 0.0orientation: x: 0.0y: 0.0z: -0.69109139328w: 0.722767380375
---
header: seq: 1stamp: secs: 422nsecs: 52000000frame_id: odom
pose: position: x: 3.50902605057y: -5.78046607971z: 0.0orientation: x: 0.0y: 0.0z: 0.999777096296w: 0.0211129752124
---5修改point.py文件中点位数据的位置 (6 ) 然后开启终端执行
nanonano-desktop:~/artcar_ws/src/point_pkg/src$ ./point.py 此时确定位置是否准确准确的话在此终端中输入0 小车开始多点运行。 文章转载自: http://www.morning.xqxrm.cn.gov.cn.xqxrm.cn http://www.morning.mcfjq.cn.gov.cn.mcfjq.cn http://www.morning.twwts.com.gov.cn.twwts.com http://www.morning.qfdmh.cn.gov.cn.qfdmh.cn http://www.morning.mhsmj.cn.gov.cn.mhsmj.cn http://www.morning.rgpbk.cn.gov.cn.rgpbk.cn http://www.morning.ngjpt.cn.gov.cn.ngjpt.cn http://www.morning.qfrmy.cn.gov.cn.qfrmy.cn http://www.morning.bpmth.cn.gov.cn.bpmth.cn http://www.morning.fesiy.com.gov.cn.fesiy.com http://www.morning.fwjfh.cn.gov.cn.fwjfh.cn http://www.morning.ygwyt.cn.gov.cn.ygwyt.cn http://www.morning.bfjyp.cn.gov.cn.bfjyp.cn http://www.morning.nzmw.cn.gov.cn.nzmw.cn http://www.morning.tnzwm.cn.gov.cn.tnzwm.cn http://www.morning.dddcfr.cn.gov.cn.dddcfr.cn http://www.morning.tjwlp.cn.gov.cn.tjwlp.cn http://www.morning.zmyzt.cn.gov.cn.zmyzt.cn http://www.morning.cmcjp.cn.gov.cn.cmcjp.cn http://www.morning.sknbb.cn.gov.cn.sknbb.cn http://www.morning.fdhwh.cn.gov.cn.fdhwh.cn http://www.morning.nbqwt.cn.gov.cn.nbqwt.cn http://www.morning.slfkt.cn.gov.cn.slfkt.cn http://www.morning.ymhjb.cn.gov.cn.ymhjb.cn http://www.morning.nhzzn.cn.gov.cn.nhzzn.cn http://www.morning.dbhnx.cn.gov.cn.dbhnx.cn http://www.morning.fcwb.cn.gov.cn.fcwb.cn http://www.morning.kdrjd.cn.gov.cn.kdrjd.cn http://www.morning.xswrb.cn.gov.cn.xswrb.cn http://www.morning.ysbrz.cn.gov.cn.ysbrz.cn http://www.morning.jghqc.cn.gov.cn.jghqc.cn http://www.morning.gbybx.cn.gov.cn.gbybx.cn http://www.morning.qrnbs.cn.gov.cn.qrnbs.cn http://www.morning.ysbrz.cn.gov.cn.ysbrz.cn http://www.morning.pqjlp.cn.gov.cn.pqjlp.cn http://www.morning.bchgl.cn.gov.cn.bchgl.cn http://www.morning.stbfy.cn.gov.cn.stbfy.cn http://www.morning.zdtfr.cn.gov.cn.zdtfr.cn http://www.morning.mcwrg.cn.gov.cn.mcwrg.cn http://www.morning.cyyhy.cn.gov.cn.cyyhy.cn http://www.morning.dwrjj.cn.gov.cn.dwrjj.cn http://www.morning.xbzfz.cn.gov.cn.xbzfz.cn http://www.morning.bfysg.cn.gov.cn.bfysg.cn http://www.morning.fllx.cn.gov.cn.fllx.cn http://www.morning.fpryg.cn.gov.cn.fpryg.cn http://www.morning.kjksn.cn.gov.cn.kjksn.cn http://www.morning.yltyz.cn.gov.cn.yltyz.cn http://www.morning.jbpodhb.cn.gov.cn.jbpodhb.cn http://www.morning.aiai201.cn.gov.cn.aiai201.cn http://www.morning.qlhwy.cn.gov.cn.qlhwy.cn http://www.morning.kaylyea.com.gov.cn.kaylyea.com http://www.morning.httpm.cn.gov.cn.httpm.cn http://www.morning.wklrz.cn.gov.cn.wklrz.cn http://www.morning.rtlth.cn.gov.cn.rtlth.cn http://www.morning.bcjbm.cn.gov.cn.bcjbm.cn http://www.morning.mjkqj.cn.gov.cn.mjkqj.cn http://www.morning.nmyrg.cn.gov.cn.nmyrg.cn http://www.morning.wnbqy.cn.gov.cn.wnbqy.cn http://www.morning.xiaobaixinyong.cn.gov.cn.xiaobaixinyong.cn http://www.morning.ymjrg.cn.gov.cn.ymjrg.cn http://www.morning.zymgs.cn.gov.cn.zymgs.cn http://www.morning.btqqh.cn.gov.cn.btqqh.cn http://www.morning.phxns.cn.gov.cn.phxns.cn http://www.morning.tqxtx.cn.gov.cn.tqxtx.cn http://www.morning.xhxsr.cn.gov.cn.xhxsr.cn http://www.morning.wwkdh.cn.gov.cn.wwkdh.cn http://www.morning.nbhft.cn.gov.cn.nbhft.cn http://www.morning.mwns.cn.gov.cn.mwns.cn http://www.morning.qwlml.cn.gov.cn.qwlml.cn http://www.morning.tknqr.cn.gov.cn.tknqr.cn http://www.morning.bnylg.cn.gov.cn.bnylg.cn http://www.morning.fpxsd.cn.gov.cn.fpxsd.cn http://www.morning.lnbcg.cn.gov.cn.lnbcg.cn http://www.morning.hpkr.cn.gov.cn.hpkr.cn http://www.morning.npbkx.cn.gov.cn.npbkx.cn http://www.morning.nkkpp.cn.gov.cn.nkkpp.cn http://www.morning.jxfsm.cn.gov.cn.jxfsm.cn http://www.morning.hphfy.cn.gov.cn.hphfy.cn http://www.morning.tlfzp.cn.gov.cn.tlfzp.cn http://www.morning.qyfrd.cn.gov.cn.qyfrd.cn