How can I subscribe to an event using ALMemory
's subscribeToEvent
function, which requires the correct Python scope while using ROS (rospy) that initiates modules outside my code?
This question is similar to this Naoqi subscription question, but differs in the sense that rospy was not used, which is critical to the implementation.
My current code is as such;
mainBehaviour.py
from nao.nao import Nao
class mainBehaviour(AbstractBehaviour):
def init(self):
global mainBehaviourMethod
mainBehaviourMethod = self
self.nao.setCallOnFall("mainBehaviourMethod", "robotHasFallen")
def update(self):
print("Update")
def robotHasFallen(self, eventName, val, subscriberIdentifier):
print("FALLING")
nao.py
from naoqi import ALProxy, ALModule, ALBroker
import rospy
from math import radians
import weakref
class Nao(object):
def __init__(self):
self.nao_ip = rospy.get_param("nao_ip")
self.port = 9559
self.memory_proxy = ALProxy("ALMemory", self.nao_ip, self.port)
def setCallOnFall(self, module, method):
self.memory_proxy.subscribeToEvent("robotHasFallen", module, method)
What I want is that mainBehaviour.py, using nao.py, has its function robotHasFallen
fire when the robot has fallen. However, the current code does not produce this behaviour (it ignores any fall), but does not produce an error either. I attempted to implement this using this ALMemory tutorial. However, this tutorial makes use of a single python file, in which methods aren't instantiated by ROS. Therefore I cannot make use of the line pythonModule = myModule("pythonModule")
. I attempted to still obtain this Python scope (on which the answer to the previously linked question states "the python variable must have the same name than the module name you create"), by declaring a global variable pointing to self
.
How can I create the desired behaviour, detecting a fallen robot using subscribeToEvent
, using ROS with its consequences of not initiating modules myself and therefore not being able to pass its constructor?
I cannot install any further libraries because I use a university computer.