demo.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import rospy
4 import math
5 import tf
6 import numpy as np
7 import time
8 from tf import TransformListener
9 from geometry_msgs.msg import PoseStamped
10 
11 class Demo():
12  def __init__(self, goals):
13  rospy.init_node('demo', anonymous=True)
14  self.worldFrame = rospy.get_param("~worldFrame", "/world")
15  self.frame = rospy.get_param("~frame")
16  self.pubGoal = rospy.Publisher('goal', PoseStamped, queue_size=1)
17  self.listener = TransformListener()
18  self.goals = goals
19  self.goalIndex = 0
20 
21  def run(self):
22  self.listener.waitForTransform(self.worldFrame, self.frame, rospy.Time(), rospy.Duration(5.0))
23  goal = PoseStamped()
24  goal.header.seq = 0
25  goal.header.frame_id = self.worldFrame
26  while not rospy.is_shutdown():
27  goal.header.seq += 1
28  goal.header.stamp = rospy.Time.now()
29  goal.pose.position.x = self.goals[self.goalIndex][0]
30  goal.pose.position.y = self.goals[self.goalIndex][1]
31  goal.pose.position.z = self.goals[self.goalIndex][2]
32  quaternion = tf.transformations.quaternion_from_euler(0, 0, self.goals[self.goalIndex][3])
33  goal.pose.orientation.x = quaternion[0]
34  goal.pose.orientation.y = quaternion[1]
35  goal.pose.orientation.z = quaternion[2]
36  goal.pose.orientation.w = quaternion[3]
37 
38  self.pubGoal.publish(goal)
39 
40  t = self.listener.getLatestCommonTime(self.worldFrame, self.frame)
41  if self.listener.canTransform(self.worldFrame, self.frame, t):
42  position, quaternion = self.listener.lookupTransform(self.worldFrame, self.frame, t)
43  rpy = tf.transformations.euler_from_quaternion(quaternion)
44  if math.fabs(position[0] - self.goals[self.goalIndex][0]) < 0.3 \
45  and math.fabs(position[1] - self.goals[self.goalIndex][1]) < 0.3 \
46  and math.fabs(position[2] - self.goals[self.goalIndex][2]) < 0.3 \
47  and math.fabs(rpy[2] - self.goals[self.goalIndex][3]) < math.radians(10) \
48  and self.goalIndex < len(self.goals) - 1:
49  rospy.sleep(self.goals[self.goalIndex][4])
50  self.goalIndex += 1
goals
Definition: demo.py:18
listener
Definition: demo.py:17
pubGoal
Definition: demo.py:16
goalIndex
Definition: demo.py:19
worldFrame
Definition: demo.py:14
def run(self)
Definition: demo.py:21
frame
Definition: demo.py:15
def __init__(self, goals)
Definition: demo.py:12


crazyflie_demo
Author(s): Wolfgang Hoenig
autogenerated on Mon Sep 28 2020 03:40:12