網(wǎng)上有很多關(guān)于一種pos機(jī)顯示屏旋轉(zhuǎn)結(jié)構(gòu), 阿克曼結(jié)構(gòu)移動(dòng)機(jī)器人的gazebo仿真的知識(shí),也有很多人為大家解答關(guān)于一種pos機(jī)顯示屏旋轉(zhuǎn)結(jié)構(gòu)的問題,今天pos機(jī)之家(www.shineka.com)為大家整理了關(guān)于這方面的知識(shí),讓我們一起來看下吧!
本文目錄一覽:
1、一種pos機(jī)顯示屏旋轉(zhuǎn)結(jié)構(gòu)
一種pos機(jī)顯示屏旋轉(zhuǎn)結(jié)構(gòu)
第三章、讓小車動(dòng)起來
1配置controller
在tianracer_description功能包新建config文件夾,通過一個(gè)yaml文件smart_control_config.yaml來聲明我們所需要的controller,以及對(duì)應(yīng)的參數(shù),PID增益和 控制器設(shè)置必須保存在yaml文件中,然后通過 launch文件加載到param服務(wù)器上:
tianracer:# controls the rear two tires based on individual motors # Publish all joint States ----------------------------------- joint_state_controller: type: joint_state_controller/JointStateController publish_rate: 50 rear_right_velocity_controller: type: velocity_controllers/JointVelocityController joint: right_rear_wheel_joint pid: {p: 100.0, i: 0.01, d: 10.0} rear_left_velocity_controller: type: velocity_controllers/JointVelocityController joint: left_rear_wheel_joint pid: {p: 100.0, i: 0.01, d: 10.0} front_right_steering_position_controller: type: effort_controllers/JointPositionController joint: right_steering_hinge_joint pid: {p: 4.0, i: 2.0, d: 1.0} front_left_steering_position_controller: type: effort_controllers/JointPositionController joint: left_steering_hinge_joint pid: {p: 4.0, i: 2.0, d: 1.0} gazebo_ros_control: pid_gains: right_rear_wheel_joint: p: 100.0 i: 0.5 d: 0.0 left_rear_wheel_joint: p: 100.0 i: 0.5 d: 0.0
2配置launch文件
創(chuàng)建一個(gè) rosLaunch 文件以啟動(dòng) ros_control controllers,使用launch文件control.launch,運(yùn)行controller_manager中的spawner,加載并運(yùn)行這些上邊這些controller:
<?xml version="1.0" encoding="UTF-8"?><launch> <!-- Load joint controller configurations from YAML file to parameter server --> <rosparam file="$(find tianracer_description)/config/smart_control_config.yaml" command="load"/> <!-- load controllers --> <node name="controller_spawner" pkg="controller_manager" type="spawner" respawn="false" output="screen" ns="/tianracer" args="joint_state_controller rear_right_velocity_controller rear_left_velocity_controller front_right_steering_position_controller front_left_steering_position_controller"/> <node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher" respawn="true" output="screen"> <remap from="/joint_states" to="/tianracer/joint_states" /> </node> <node name="cmdvel2gazebo" pkg="tianracer_description" type="cmdvel2gazebo.py" respawn="true" output="screen"/></launch>
接著創(chuàng)建一個(gè)可以將小車模型在gazeboi中打開的launch文件tianracer.launch,并且能夠加載上述control.launch文件
<?xml version="1.0" encoding="UTF-8"?><launch> <!-- 設(shè)置launch文件的參數(shù) --> <arg name="paused" default="false"/> <arg name="use_sim_time" default="true"/> <arg name="gui" default="true"/> <arg name="headless" default="false"/> <arg name="debug" default="false"/> <!--模型車的起點(diǎn)放置位置--> <arg name="x_pos" default="0"/> <arg name="y_pos" default="0"/> <arg name="z_pos" default="0"/> <arg name="R_pos" default="0"/> <arg name="P_pos" default="0"/> <arg name="Y_pos" default="0"/> <!--運(yùn)行g(shù)azebo仿真環(huán)境--> <include file="$(find gazebo_ros)/launch/empty_world.launch"> <arg name="debug" value="$(arg debug)" /> <arg name="gui" value="$(arg gui)" /> <arg name="paused" value="$(arg paused)"/> <arg name="use_sim_time" value="$(arg use_sim_time)"/> <arg name="headless" value="$(arg headless)"/> <!-- <arg name="world_name" value="$(find racebot_description)/world/tianracer_race.world"/> --> <!-- .world文件的地址--> </include> <!-- 加載機(jī)器人模型描述參數(shù) --> <param name="robot_description" command="$(find xacro)/xacro --inorder '$(find tianracer_description)/urdf/tianracer_description.xacro'"/> <!-- 在gazebo中加載機(jī)器人模型--> <node name="urdf_spawner" pkg="gazebo_ros" type="spawn_model" respawn="false" output="screen" args="-urdf -model tianracer -param robot_description -x $(arg x_pos) -y $(arg y_pos) -z $(arg z_pos) -R $(arg R_pos) -P $(arg P_pos) -Y $(arg Y_pos)"/> <!-- ros_control racecar launch file --> <include file="$(find tianracer_description)/launch/control.launch"> </include> <!--Launch the simulation joystick control--> <!-- <rosparam command="load" file="$(find tianracer_gazebo)/config/keyboard_teleop.yaml" /> <node pkg="tianracer_gazebo" type="keyboard_teleop.py" name="keyboard_teleop" /> --></launch>
3配置運(yùn)動(dòng)學(xué)模型
在功能包中新建scripts文件夾,并加入cmdvei2gazebo.py文件,該文件用的是
【從零開始自動(dòng)駕駛】07 用 ROS topic 控制車輪_嗶哩嗶哩_bilibili中的開源代碼,其中代碼的解析這里不做展開復(fù)述,各位請(qǐng)自行到原地址觀看,up主講的很好。該文件定義了小車的運(yùn)動(dòng)學(xué)模型,并且訂閱了一個(gè)Twist消息類型的話題tianracer/cmd_vel,我們可以通過編寫一個(gè)接收該消息類型話題的節(jié)點(diǎn)來控制小車運(yùn)動(dòng)。代碼如下:
#!/usr/bin/env pythonimport rospyfrom std_msgs.msg import Float64from geometry_msgs.msg import Twistimport mathclass CmdVel2Gazebo: def __init__(self): rospy.init_node('cmdvel2gazebo', anonymous=True) rospy.Subscriber('/tianracer/cmd_vel', Twist, self.callback, queue_size=1) self.pub_steerL = rospy.Publisher('/tianracer/front_left_steering_position_controller/command', Float64, queue_size=1) self.pub_steerR = rospy.Publisher('/tianracer/front_right_steering_position_controller/command', Float64, queue_size=1) self.pub_rearL = rospy.Publisher('/tianracer/rear_left_velocity_controller/command', Float64, queue_size=1) self.pub_rearR = rospy.Publisher('/tianracer/rear_right_velocity_controller/command', Float64, queue_size=1) # initial velocity and tire angle are 0 self.x = 0 self.z = 0 # car Wheelbase (in m) self.L = 0.261 # car Tread self.T_front = 0.1632 self.T_rear = 0.1632 # how many seconds delay for the dead man's switch self.timeout=rospy.Duration.from_sec(0.2); self.lastMsg=rospy.Time.now() # maximum steer angle of the "inside" tire self.maxsteerInside=0.6; # turning radius for maximum steer angle just with the inside tire # tan(maxsteerInside) = wheelbase/radius --> solve for max radius at this angle rMax = self.L/math.tan(self.maxsteerInside); # radius of inside tire is rMax, so radius of the ideal middle tire (rIdeal) is rMax+treadwidth="360px",height="auto" />
msgs_too_old = delta_last_msg_time > self.timeout if msgs_too_old: self.x = 0 msgRear = Float64() msgRear.data = self.x self.pub_rearL.publish(msgRear) self.pub_rearR.publish(msgRear) msgSteer = Float64() msgSteer.data = 0 self.pub_steerL.publish(msgSteer) self.pub_steerR.publish(msgSteer) return # The self.z is the delta angle in radians of the imaginary front wheel of ackerman model. if self.z != 0: T_rear = self.T_rear T_front = self.T_front L=self.L # self.v is the linear *velocity* r = L/math.fabs(math.tan(self.z)) rL_rear = r-(math.copysign(1,self.z)*(T_rear/2.0)) rR_rear = r+(math.copysign(1,self.z)*(T_rear/2.0)) rL_front = r-(math.copysign(1,self.z)*(T_front/2.0)) rR_front = r+(math.copysign(1,self.z)*(T_front/2.0)) msgRearR = Float64() # the right tire will go a little faster when we turn left (positive angle) # amount is proportional to the radius of the outside/ideal msgRearR.data = self.x*rR_rear/r; msgRearL = Float64() # the left tire will go a little slower when we turn left (positive angle) # amount is proportional to the radius of the inside/ideal msgRearL.data = self.x*rL_rear/r; self.pub_rearL.publish(msgRearL) self.pub_rearR.publish(msgRearR) msgSteerL = Float64() msgSteerR = Float64() # the left tire's angle is solved directly from geometry msgSteerL.data = math.atan2(L,rL_front)*math.copysign(1,self.z) self.pub_steerL.publish(msgSteerL) # the right tire's angle is solved directly from geometry msgSteerR.data = math.atan2(L,rR_front)*math.copysign(1,self.z) self.pub_steerR.publish(msgSteerR) else: # if we aren't turning msgRear = Float64() msgRear.data = self.x; self.pub_rearL.publish(msgRear) # msgRear.data = 0; self.pub_rearR.publish(msgRear) msgSteer = Float64() msgSteer.data = self.z self.pub_steerL.publish(msgSteer) self.pub_steerR.publish(msgSteer)if __name__ == '__main__': try: CmdVel2Gazebo() except rospy.ROSInterruptException: pass將代碼中的話題名以及參數(shù)進(jìn)行修改,改為自己小車模型的尺寸參數(shù)。并將該python代碼作為一個(gè)節(jié)點(diǎn)添加到control .launch文件中。
4讓小車動(dòng)起來
通過rostopic pub話題讓小車動(dòng)起來
到此為止已經(jīng)可以通過pub話題讓小車動(dòng)起來了。
roslaunch tianracer_description tianracer.launch
再開一個(gè)終端,使用rostopic list來看一下話題列表
rostopic list
可以看到發(fā)布了單目攝像頭,深度攝像頭,激光雷達(dá),以及讓小車運(yùn)動(dòng)的tianracer/cmd_vel話題,將這個(gè)話題pub一下:
rostopic pub /tianracer/cmd_vel -r 10 geometry_msgs/Twist "linear: x: 1.0 y: 0.0 z: 0.0angular: x: 0.0 y: 0.0 z: 1.0"
此時(shí)小車便會(huì)繞著Z軸轉(zhuǎn)動(dòng)起來。
使用鍵盤控制節(jié)點(diǎn)控制小車運(yùn)動(dòng)
在tianracer_description/scripts目錄下新建teleop.py
#!/usr/bin/env python# -*- coding: utf-8 -*-import rospyfrom geometry_msgs.msg import Twistimport sys, select, termios, ttymsg = """Control mbot!---------------------------Moving around: u i o j k l m , .q/z : increase/decrease max speeds by 10%w/x : increase/decrease only linear speed by 10%e/c : increase/decrease only angular speed by 10%space key, k : force stopanything else : stop smoothlyCTRL-C to quit"""moveBindings = { 'i':(1,0), 'o':(1,-1), 'j':(0,1), 'l':(0,-1), 'u':(1,1), ',':(-1,0), '.':(-1,1), 'm':(-1,-1), }speedBindings={ 'q':(1.1,1.1), 'z':(.9,.9), 'w':(1.1,1), 'x':(.9,1), 'e':(1,1.1), 'c':(1,.9), }def getKey(): tty.setraw(sys.stdin.fileno()) rlist, _, _ = select.select([sys.stdin], [], [], 0.1) if rlist: key = sys.stdin.read(1) else: key = '' termios.tcsetattr(sys.stdin, termios.TCSADRAIN, settings) return keyspeed = 10turn = 1def vels(speed,turn): return "currently:\speed %surn %s " % (speed,turn)if __name__=="__main__": settings = termios.tcgetattr(sys.stdin) rospy.init_node('carsmart_teleop') pub = rospy.Publisher('/tianracer/cmd_vel', Twist, queue_size=5) x = 0 th = 0 status = 0 count = 0 acc = 0.1 target_speed = 0 target_turn = 0 control_speed = 0 control_turn = 0 try: print msg print vels(speed,turn) while(1): key = getKey() # 運(yùn)動(dòng)控制方向鍵(1:正方向,-1負(fù)方向) if key in moveBindings.keys(): x = moveBindings[key][0] th = moveBindings[key][1] count = 0 # 速度修改鍵 elif key in speedBindings.keys(): speed = speed * speedBindings[key][0] # 線速度增加0.1倍 turn = turn * speedBindings[key][1] # 角速度增加0.1倍 count = 0 print vels(speed,turn) if (status == 14): print msg status = (status + 1) % 15 # 停止鍵 elif key == ' ' or key == 'k' : x = 0 th = 0 control_speed = 0 control_turn = 0 else: count = count + 1 if count > 4: x = 0 th = 0 if (key == '\\x03'): break # 目標(biāo)速度=速度值*方向值 target_speed = speed * x target_turn = turn * th # 速度限位,防止速度增減過快 if target_speed > control_speed: control_speed = min( target_speed, control_speed + 0.02 ) elif target_speed < control_speed: control_speed = max( target_speed, control_speed - 0.02 ) else: control_speed = target_speed if target_turn > control_turn: control_turn = min( target_turn, control_turn + 0.1 ) elif target_turn < control_turn: control_turn = max( target_turn, control_turn - 0.1 ) else: control_turn = target_turn # 創(chuàng)建并發(fā)布twist消息 twist = Twist() twist.linear.x = control_speed; twist.linear.y = 0; twist.linear.z = 0 twist.angular.x = 0; twist.angular.y = 0; twist.angular.z = control_turn pub.publish(twist) except: print e finally: twist = Twist() twist.linear.x = 0; twist.linear.y = 0; twist.linear.z = 0 twist.angular.x = 0; twist.angular.y = 0; twist.angular.z = 0 pub.publish(twist) termios.tcsetattr(sys.stdin, termios.TCSADRAIN, settings)
該節(jié)點(diǎn)發(fā)布了一個(gè)Twist消息類型的話題tianracer/cmd_vel,可以通過鍵盤來控制小車運(yùn)動(dòng)。
roslaunch tianracer_description tianracer.launch rosrun tianracer_description teleop.py
此時(shí)按u,i,o等按鍵即可控制小車運(yùn)動(dòng)了,通過rqt_graph看一下各個(gè)節(jié)點(diǎn)之間的關(guān)系:
rqt_graph
5小結(jié)
至此,已經(jīng)成功讓小車動(dòng)起來了,而且也添加了激光雷達(dá)傳感器,這也就意味著接下去就能做建圖導(dǎo)航了,然而由于從solidworks導(dǎo)出的模型慣性參數(shù)等方面的一些問題,導(dǎo)致小車運(yùn)動(dòng)起來多多少少有一些問題,所以我手?jǐn)]了小車的1:1簡(jiǎn)易模型的代碼,并且準(zhǔn)備用ackermann消息控制小車運(yùn)動(dòng),并使用該模型完成接下去的建圖導(dǎo)航等內(nèi)容。
參考資料:
1.古月老師的《ROS機(jī)器人開發(fā)實(shí)踐》
2.[從零駕駛自動(dòng)駕駛] https://www.bilibili.com/video/BV1ZJ41187tS?spm_id_from=333.999.0.0
以上就是關(guān)于一種pos機(jī)顯示屏旋轉(zhuǎn)結(jié)構(gòu), 阿克曼結(jié)構(gòu)移動(dòng)機(jī)器人的gazebo仿真的知識(shí),后面我們會(huì)繼續(xù)為大家整理關(guān)于一種pos機(jī)顯示屏旋轉(zhuǎn)結(jié)構(gòu)的知識(shí),希望能夠幫助到大家!
