send_waypoint_file.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 
17 import rospy
18 import sys
19 from uuv_control_msgs.srv import InitWaypointsFromFile
20 from std_msgs.msg import String, Time
21 
22 
23 if __name__ == '__main__':
24  rospy.init_node('send_waypoint_file')
25  rospy.loginfo('Send a waypoint file, namespace=%s', rospy.get_namespace())
26 
27  if rospy.is_shutdown():
28  rospy.logerr('ROS master not running!')
29  sys.exit(-1)
30 
31  if rospy.has_param('~filename'):
32  filename = rospy.get_param('~filename')
33  else:
34  raise rospy.ROSException('No filename found')
35 
36  # If no start time is provided: start *now*.
37  start_time = rospy.Time.now().to_sec()
38  start_now = True
39  if rospy.has_param('~start_time'):
40  start_time = rospy.get_param('~start_time')
41  if start_time < 0.0:
42  rospy.logerr('Negative start time, setting it to 0.0')
43  start_time = 0.0
44  start_now = True
45  else:
46  start_now = False
47  else:
48  start_now = True
49 
50  rospy.loginfo('Start time=%.2f s' % start_time)
51 
52  interpolator = rospy.get_param('~interpolator', 'lipb')
53 
54  try:
55  rospy.wait_for_service('init_waypoints_from_file', timeout=30)
56  except rospy.ROSException:
57  raise rospy.ROSException('Service not available! Closing node...')
58 
59  try:
60  init_wp = rospy.ServiceProxy(
61  'init_waypoints_from_file',
62  InitWaypointsFromFile)
63  except rospy.ServiceException as e:
64  raise rospy.ROSException('Service call failed, error=%s', str(e))
65 
66  success = init_wp(Time(rospy.Time.from_sec(start_time)),
67  start_now,
68  String(filename),
69  String(interpolator))
70 
71  if success:
72  rospy.loginfo('Waypoints file successfully received, '
73  'filename=%s', filename)
74  else:
75  rospy.loginfo('Failed to send waypoints')


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