Skip to content

Commit

Permalink
Merge pull request #6 from chenjy9581/melodic
Browse files Browse the repository at this point in the history
Melodic
  • Loading branch information
anchuanxu authored Aug 25, 2019
2 parents 7d12f87 + 8da579b commit c67dcfd
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 46 deletions.
10 changes: 5 additions & 5 deletions robot_sim_demo/scripts/robot_keyboard_teleop.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ def vels(speed,turn):
control_speed = 0
control_turn = 0
try:
print msg
print vels(speed,turn)
print (msg)
print (vels(speed,turn))
while(1):
key = getKey()
if key in moveBindings.keys():
Expand All @@ -88,9 +88,9 @@ def vels(speed,turn):
turn = turn * speedBindings[key][1]
count = 0

print vels(speed,turn)
print (vels(speed,turn))
if (status == 14):
print msg
print (msg)
status = (status + 1) % 15
elif key == ' ' or key == 'k' :
x = 0
Expand Down Expand Up @@ -132,7 +132,7 @@ def vels(speed,turn):
#print("publihsed: vx: {0}, wz: {1}".format(twist.linear.x, twist.angular.z))

except:
print e
print (e)

finally:
twist = Twist()
Expand Down
4 changes: 2 additions & 2 deletions service_demo/scripts/client_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ def client_srv():

# 打印处理结果,注意调用response的方法,类似于从resp对象中调取response属性
rospy.loginfo("Message From server:%s"%resp.feedback)
except rospy.ServiceException, e:
rospy.logwarn("Service call failed: %s"%e)
except rospy.ServiceException:
rospy.logwarn("Service call failed: %s"%rospy.ServiceException)

# 如果单独运行此文件,则将上面函数client_srv()作为主函数运行
if __name__=="__main__":
Expand Down
58 changes: 29 additions & 29 deletions tf_demo/scripts/py_coordinate_transformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,63 +8,63 @@
if __name__ == '__main__':
rospy.init_node('py_coordinate_transformation')
#第1部分,定义空间点和空间向量
print '第1部分,定义空间点和空间向量'
print ('第1部分,定义空间点和空间向量')
#1.1 返回均匀随机单位四元数
q=tf.transformations.random_quaternion(rand=None)
print '定义均匀随机四元数:'
print q
print ('定义均匀随机四元数:')
print (q)
#1.2 返回均匀随机单位旋转矩阵
m=tf.transformations.random_rotation_matrix(rand=None)
print '定义均匀随机单位旋转矩阵:'
print m
print ('定义均匀随机单位旋转矩阵:')
print (m)
#1.3 返回均匀随机单位向量
v=tf.transformations.random_vector(3)
print '定义均匀随机单位向量:'
print v
print ('定义均匀随机单位向量:')
print (v)
#1.4 通过向量来求旋转矩阵
v_m=tf.transformations.translation_matrix(v)
print '通过向量来求旋转矩阵:'
print v_m
print ('通过向量来求旋转矩阵:')
print (v_m)
#1.5 通过旋转矩阵来求向量
m_v=tf.transformations.translation_from_matrix(m)
print '通过旋转矩阵来求向量:'
print m_v
print ('通过旋转矩阵来求向量:')
print (m_v)
#第2部分,定义四元数
print '第2部分,定义四元数'
print ('第2部分,定义四元数')
#2.1 通过旋转轴和旋转角返回四元数
axis_q=tf.transformations.quaternion_about_axis(0.123, (1, 0, 0))
print '通过旋转轴和旋转角返回四元数:'
print axis_q
print ('通过旋转轴和旋转角返回四元数:')
print (axis_q)
#2.2 返回四元数的共轭
n_q=tf.transformations.quaternion_conjugate(q)
print '返回四元数q的共轭:'
print n_q
print ('返回四元数q的共轭:')
print (n_q)
#2.3 从欧拉角和旋转轴,求四元数
o_q=tf.transformations.quaternion_from_euler(1, 2, 3, 'ryxz')
print '从欧拉角和旋转轴,求四元数:'
print o_q
print ('从欧拉角和旋转轴,求四元数:')
print (o_q)
#2.4 从旋转矩阵中,返回四元数
m_q=tf.transformations.quaternion_from_matrix(m)
print '从旋转矩阵中,返回四元数:'
print m_q
print ('从旋转矩阵中,返回四元数:')
print (m_q)
#2.5 两个四元数相乘
qxq=tf.transformations.quaternion_multiply(q,n_q)
print '两个四元数相乘'
print qxq
print ('两个四元数相乘')
print (qxq)
#第3部分,定义欧拉角度
print '第3部分,定义欧拉角'
print ('第3部分,定义欧拉角')
#3.1 从欧拉角和旋转轴返回旋转矩阵
rpy_m=tf.transformations.euler_matrix(1, 2, 3, 'syxz')
print '从欧拉角和旋转轴返回旋转矩阵'
print rpy_m
print ('从欧拉角和旋转轴返回旋转矩阵')
print (rpy_m)
#3.2 由旋转矩阵和特定的旋转轴返回欧拉角
m_rpy=tf.transformations.euler_from_matrix(m)
print '由旋转矩阵和特定的旋转轴返回欧拉角'
print m_rpy
print ('由旋转矩阵和特定的旋转轴返回欧拉角')
print (m_rpy)
#3.3 由四元数和特定的轴得到欧拉角
q_rpy=tf.transformations.euler_from_quaternion(q)
print '由四元数和特定的轴得到欧拉角'
print q_rpy
print ('由四元数和特定的轴得到欧拉角')
print (q_rpy)



4 changes: 2 additions & 2 deletions tf_demo/scripts/py_tf_broadcaster.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

if __name__ == '__main__':
rospy.init_node('py_tf_broadcaster')
print '讲解tf.transformBroadcaster类'
print '第1种发布方式:sendTransform(translation,rotation,time,child,parent)'
print ('讲解tf.transformBroadcaster类')
print ('第1种发布方式:sendTransform(translation,rotation,time,child,parent)')
#第一部分,发布sendTransform(translation,rotation,time,child,parent)
br = tf.TransformBroadcaster()
#输入相对原点的值和欧拉角
Expand Down
4 changes: 2 additions & 2 deletions tf_demo/scripts/py_tf_broadcaster02.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

if __name__ == '__main__':
rospy.init_node('py_tf_broadcaster')
print '讲解tf.transformBroadcaster类'
print '第2种发布方式:sendTransformMessage(transform)'
print ('讲解tf.transformBroadcaster类')
print ('第2种发布方式:sendTransformMessage(transform)')
#第二部分,发布sendTransformMessage(transform)
m=tf.TransformBroadcaster()
t = geometry_msgs.msg.TransformStamped()
Expand Down
10 changes: 5 additions & 5 deletions tf_demo/scripts/py_tf_listerner.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@
listener = tf.TransformListener() #TransformListener创建后就开始接受tf广播信息,最多可以缓存10s 目前存在的问题,是四个数值的顺序我还有点问题
rate = rospy.Rate(1.0)
#1. 阻塞直到frame相通
print '1. 阻塞直到frame相通'
print ('1. 阻塞直到frame相通')
listener.waitForTransform("/base_link", "/link1", rospy.Time(), rospy.Duration(4.0))
while not rospy.is_shutdown():
try:
#2. 监听对应的tf,返回平移和旋转
print '2. 监听对应的tf,返回平移和旋转'
print ('2. 监听对应的tf,返回平移和旋转')
(trans,rot) = listener.lookupTransform('/base_link', '/link1', rospy.Time(0)) #rospy.Time(0)不表示0时刻的tf,而是指最近一帧tf
except (tf.LookupException, tf.ConnectivityException, tf.ExtrapolationException):
continue

rospy.loginfo('距离原点的位置: x=%f ,y= %f,z=%f \n 旋转四元数: w=%f ,x= %f,y=%f z=%f ',trans[0],trans[1],trans[2],rot[0],rot[1],rot[2],rot[3])
#3. 判断两个frame是否相通
print '3. 判断两个frame是否相通'
print ('3. 判断两个frame是否相通')
if listener.canTransform('/link1','/base_link',rospy.Time(0)) :
print 'true'
print ('true')
else :
print 'false'
print ('false')
rate.sleep()
2 changes: 1 addition & 1 deletion tf_follower/scripts/py_tf_follower.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
def shutdownhook():
# works better than the rospy.is_shut_down()
global ctrl_c
print "shutdown time! Stop the robot"
print ("shutdown time! Stop the robot")
cmd = geometry_msgs.msg.Twist()
cmd.linear.x = 0.0
cmd.angular.z = 0.0
Expand Down

0 comments on commit c67dcfd

Please sign in to comment.