-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathnav_application
executable file
·117 lines (101 loc) · 4.07 KB
/
nav_application
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
nav_application
Using task_node, it adds the ability to stop the task spinning
and take back manual control over the multicopter
FlyingROS is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
FlyingROS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FlyingROS. If not, see <http://www.gnu.org/licenses/>.
Software created by Alexis Paques and Nabil Nehri for the UCL
in a Drone-Based Additive Manufacturing of Architectural Structures
project financed by the MIT Seed Fund
Originaly published by Vladimir Ermakov (c) 2015 under GNU GPLv3
Copyright (c) Alexis Paques 2016
"""
import rospy
import mavros
import urwid
import urwid_app
from flyingros_msgs.msg import Task, Mission
from flyingros_msgs.srv import TaskRequest, MissionRequest, TaskHandle, MissionHandle, TaskRequestResponse, MissionRequestResponse, TaskHandleResponse, MissionHandleResponse
from std_srvs.srv import SetBool, SetBoolResponse
from geometry_msgs.msg import PoseStamped, Point
from mavros.utils import *
from flyingros_libs.tasks import *
import sys
def handle_current_task(task):
pass
#rospy.loginfo('info')
def spin_switch(data):
global spinning, app, spin_enable_srv
if spinning :
app.setSpinning(False)
spin_enable_srv(False)
spinning = False
else :
app.setSpinning(True)
spin_enable_srv(True)
spinning = True
def update_mission(data):
global mission_get_srv, app
try:
response = mission_get_srv()
app.refresh_mission(response.mission)
except rospy.ServiceException, e:
pass
#rospy.loginfo("Service call failed: {0}".format(e))
def main():
global spinning, app
app = urwid_app.App(update_mission=update_mission, spin_switch=spin_switch)
app.run()
app.setSpinning(True)
# main urwid closes when user ask to
# rospy.spin() no need to spin ros in Python
def subscribers():
global current_pub
global mission_add_srv, mission_get_srv, mission_remove_srv, task_add_srv, task_get_srv, task_remove_srv, spin_enable_srv
# Services
# - missions
rospy.wait_for_service('flyingros/controller/mission/add')
mission_add_srv = rospy.ServiceProxy('flyingros/controller/mission/add', MissionHandle)
rospy.wait_for_service('flyingros/controller/mission/get')
mission_get_srv = rospy.ServiceProxy('flyingros/controller/mission/get', MissionRequest)
rospy.wait_for_service('flyingros/controller/mission/remove')
mission_remove_srv = rospy.ServiceProxy('flyingros/controller/mission/remove', MissionRequest)
# - tasks
rospy.wait_for_service('flyingros/controller/task/add')
task_add_srv = rospy.ServiceProxy('flyingros/controller/task/add', TaskHandle)
rospy.wait_for_service('flyingros/controller/task/get')
task_get_srv = rospy.ServiceProxy('flyingros/controller/task/get', TaskRequest)
rospy.wait_for_service('flyingros/controller/task/remove')
task_remove_srv = rospy.ServiceProxy('flyingros/controller/task/remove', TaskHandle)
# - spinning
rospy.wait_for_service('flyingros/controller/spinning')
spin_enable_srv = rospy.ServiceProxy('flyingros/controller/spinning', SetBool)
# Subscribers
current_sub = rospy.Subscriber('flyingros/controller/task/current', Task, handle_current_task)
def init():
# Input data
# Objects
global spinning
spinning = True
# Node initiation
rospy.init_node('nav_application_urwid')
# Data initiation
if __name__ == '__main__':
#rospy.loginfo("We are ready")
try:
init()
subscribers()
main()
except rospy.ROSInterruptException:
#rospy.loginfo("init failed")
pass