45 lines
1.1 KiB
Python
Executable File
45 lines
1.1 KiB
Python
Executable File
#! /usr/bin/env python
|
|
import rospy
|
|
|
|
from teleoperation.srv import InformController, InformControllerResponse
|
|
|
|
|
|
STATE = 'idle' # Also walk, imitate and fallen
|
|
|
|
|
|
def handle_request(r):
|
|
module = r.module
|
|
message = r.message
|
|
global STATE
|
|
|
|
if module == 'walker':
|
|
if message == 'move':
|
|
if STATE in ('idle', 'walk'):
|
|
STATE = 'walk'
|
|
permission = True
|
|
else:
|
|
permission = False
|
|
elif message == 'stop':
|
|
if STATE == 'walk':
|
|
STATE = 'idle'
|
|
permission = True
|
|
|
|
elif module == 'fall_detector':
|
|
permission = True
|
|
if message in ('falling', 'fallen'):
|
|
STATE = 'fallen'
|
|
elif message == 'recovered':
|
|
STATE = 'idle'
|
|
|
|
print 'Got request from %s to %s. Permission: %s. State is now: %s.' % (
|
|
module, message, permission, STATE
|
|
)
|
|
return InformControllerResponse(permission)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
rospy.init_node('controller')
|
|
ic = rospy.Service('inform_controller', InformController, handle_request)
|
|
rospy.spin()
|
|
# initialize stuff
|