start_circular_trajectory.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # Copyright (c) 2016 The UUV Simulator Authors.
3 # All rights reserved.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 from __future__ import print_function
17 import rospy
18 import sys
19 from uuv_control_msgs.srv import InitCircularTrajectory
20 from numpy import pi
21 from geometry_msgs.msg import Point
22 from std_msgs.msg import Time
23 
24 
25 if __name__ == '__main__':
26  print('Starting the circular trajectory creator')
27  rospy.init_node('start_circular_trajectory')
28 
29  if rospy.is_shutdown():
30  print('ROS master not running!')
31  sys.exit(-1)
32 
33  # If no start time is provided: start *now*.
34  start_time = rospy.Time.now().to_sec()
35  start_now = False
36  if rospy.has_param('~start_time'):
37  start_time = rospy.get_param('~start_time')
38  if start_time < 0.0:
39  print('Negative start time, setting it to 0.0')
40  start_time = 0.0
41  start_now = True
42  else:
43  start_now = True
44 
45  param_labels = ['radius', 'center', 'n_points', 'heading_offset',
46  'duration', 'max_forward_speed']
47  params = dict()
48 
49  for label in param_labels:
50  if not rospy.has_param('~' + label):
51  print('{} must be provided for the trajectory generation!'.format(label))
52  sys.exit(-1)
53 
54  params[label] = rospy.get_param('~' + label)
55 
56  if len(params['center']) != 3:
57  print('Center of circle must have 3 components (x, y, z)')
58  sys.exit(-1)
59 
60  if params['n_points'] <= 2:
61  print('Number of points must be at least 2')
62  sys.exit(-1)
63 
64  if params['max_forward_speed'] <= 0:
65  print('Velocity limit must be positive')
66  sys.exit(-1)
67 
68  try:
69  rospy.wait_for_service('start_circular_trajectory', timeout=20)
70  except rospy.ROSException:
71  print('Service not available! Closing node...')
72  sys.exit(-1)
73 
74  try:
75  traj_gen = rospy.ServiceProxy('start_circular_trajectory', InitCircularTrajectory)
76  except rospy.ServiceException as e:
77  print('Service call failed, error={}'.format(e))
78  sys.exit(-1)
79 
80  print('Generating trajectory that starts at t={} s'.format(start_time))
81 
82  success = traj_gen(Time(rospy.Time(start_time)),
83  start_now,
84  params['radius'],
85  Point(params['center'][0], params['center'][1], params['center'][2]),
86  False,
87  0.0,
88  params['n_points'],
89  params['heading_offset'] * pi / 180,
90  params['max_forward_speed'],
91  params['duration'])
92 
93  if success:
94  print('Trajectory successfully generated!')
95  else:
96  print('Failed')


uuv_control_utils
Author(s): Musa Morena Marcusso Manhaes , Sebastian Scherer , Luiz Ricardo Douat
autogenerated on Mon Jul 1 2019 19:39:33