crazyflie.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import rospy
4 import numpy as np
5 from crazyflie_driver.srv import *
6 from crazyflie_driver.msg import TrajectoryPolynomialPiece
7 
9  return geometry_msgs.msg.Point(a[0], a[1], a[2])
10 
11 class Crazyflie:
12  def __init__(self, prefix, tf):
13  self.prefix = prefix
14  self.tf = tf
15 
16  rospy.wait_for_service(prefix + "/set_group_mask")
17  self.setGroupMaskService = rospy.ServiceProxy(prefix + "/set_group_mask", SetGroupMask)
18  rospy.wait_for_service(prefix + "/takeoff")
19  self.takeoffService = rospy.ServiceProxy(prefix + "/takeoff", Takeoff)
20  rospy.wait_for_service(prefix + "/land")
21  self.landService = rospy.ServiceProxy(prefix + "/land", Land)
22  rospy.wait_for_service(prefix + "/stop")
23  self.stopService = rospy.ServiceProxy(prefix + "/stop", Stop)
24  rospy.wait_for_service(prefix + "/go_to")
25  self.goToService = rospy.ServiceProxy(prefix + "/go_to", GoTo)
26  rospy.wait_for_service(prefix + "/upload_trajectory")
27  self.uploadTrajectoryService = rospy.ServiceProxy(prefix + "/upload_trajectory", UploadTrajectory)
28  rospy.wait_for_service(prefix + "/start_trajectory")
29  self.startTrajectoryService = rospy.ServiceProxy(prefix + "/start_trajectory", StartTrajectory)
30  rospy.wait_for_service(prefix + "/update_params")
31  self.updateParamsService = rospy.ServiceProxy(prefix + "/update_params", UpdateParams)
32 
33  def setGroupMask(self, groupMask):
34  self.setGroupMaskService(groupMask)
35 
36  def takeoff(self, targetHeight, duration, groupMask = 0):
37  self.takeoffService(groupMask, targetHeight, rospy.Duration.from_sec(duration))
38 
39  def land(self, targetHeight, duration, groupMask = 0):
40  self.landService(groupMask, targetHeight, rospy.Duration.from_sec(duration))
41 
42  def stop(self, groupMask = 0):
43  self.stopService(groupMask)
44 
45  def goTo(self, goal, yaw, duration, relative = False, groupMask = 0):
46  gp = arrayToGeometryPoint(goal)
47  self.goToService(groupMask, relative, gp, yaw, rospy.Duration.from_sec(duration))
48 
49  def uploadTrajectory(self, trajectoryId, pieceOffset, trajectory):
50  pieces = []
51  for poly in trajectory.polynomials:
52  piece = TrajectoryPolynomialPiece()
53  piece.duration = rospy.Duration.from_sec(poly.duration)
54  piece.poly_x = poly.px.p
55  piece.poly_y = poly.py.p
56  piece.poly_z = poly.pz.p
57  piece.poly_yaw = poly.pyaw.p
58  pieces.append(piece)
59  self.uploadTrajectoryService(trajectoryId, pieceOffset, pieces)
60 
61  def startTrajectory(self, trajectoryId, timescale = 1.0, reverse = False, relative = True, groupMask = 0):
62  self.startTrajectoryService(groupMask, trajectoryId, timescale, reverse, relative)
63 
64  def position(self):
65  self.tf.waitForTransform("/world", "/cf" + str(self.id), rospy.Time(0), rospy.Duration(10))
66  position, quaternion = self.tf.lookupTransform("/world", "/cf" + str(self.id), rospy.Time(0))
67  return np.array(position)
68 
69  def getParam(self, name):
70  return rospy.get_param(self.prefix + "/" + name)
71 
72  def setParam(self, name, value):
73  rospy.set_param(self.prefix + "/" + name, value)
74  self.updateParamsService([name])
75 
76  def setParams(self, params):
77  for name, value in params.iteritems():
78  rospy.set_param(self.prefix + "/" + name, value)
79  self.updateParamsService(params.keys())
def land(self, targetHeight, duration, groupMask=0)
Definition: crazyflie.py:39
def goTo(self, goal, yaw, duration, relative=False, groupMask=0)
Definition: crazyflie.py:45
def getParam(self, name)
Definition: crazyflie.py:69
def uploadTrajectory(self, trajectoryId, pieceOffset, trajectory)
Definition: crazyflie.py:49
def stop(self, groupMask=0)
Definition: crazyflie.py:42
def __init__(self, prefix, tf)
Definition: crazyflie.py:12
def setGroupMask(self, groupMask)
Definition: crazyflie.py:33
def setParam(self, name, value)
Definition: crazyflie.py:72
def position(self)
Definition: crazyflie.py:64
def takeoff(self, targetHeight, duration, groupMask=0)
Definition: crazyflie.py:36
def setParams(self, params)
Definition: crazyflie.py:76
def startTrajectory(self, trajectoryId, timescale=1.0, reverse=False, relative=True, groupMask=0)
Definition: crazyflie.py:61
def arrayToGeometryPoint(a)
Definition: crazyflie.py:8


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