<commit_before>#! /usr/bin/env python

import rospy
import sys
# Brings in the SimpleActionClient
import actionlib
import topological_navigation.msg
from strands_navigation_msgs.msg import TopologicalMap
from std_srvs.srv import Empty

class topol_map_info(object):
    def __init__(self) :
        self.sub = rospy.Subscriber("/topological_map", TopologicalMap, self._callback)
        rospy.loginfo(" ... done with subscribing map")
        self._node_names = None

    def _callback(self, msg):
        if self._node_names is None :
            self._node_names = set([n.name for n in msg.nodes])
            self._node_names.remove('ChargingPoint')
                
    def hasNames(self):
        return not self._node_names is None
        
    def getNames(self):
        return self._node_names

class topol_nav_client(object):
    def __init__(self) :
        rospy.on_shutdown(self._on_node_shutdown)
        self.client = actionlib.SimpleActionClient('topological_navigation', topological_navigation.msg.GotoNodeAction)
        self.client.wait_for_server()
        rospy.loginfo(" ... Init done")
        
    def call_action(self, targ):
        navgoal = topological_navigation.msg.GotoNodeGoal()
    
        print "Requesting Navigation to %s" %targ
    
        navgoal.target = targ
        #navgoal.origin = orig
    
        # Sends the goal to the action server.
        self.client.send_goal(navgoal)#,self.done_cb, self.active_cb, self.feedback_cb)
    
        # Waits for the server to finish performing the action.
        self.client.wait_for_result()
    
        # Prints out the result of executing the action
        ps = self.client.get_result()  # A FibonacciResult
        print ps        

    def cancle_action(self):
        self.client.cancel_all_goals()

    def _on_node_shutdown(self):
        self.client.cancel_all_goals()
        #sleep(2)

class random_walker(object):
    def __init__(self, names) :
        self._running = True
        self._action = topol_nav_client()
        self._names = names
        self._start_server = rospy.Service('/start_random_walk', Empty, self._start_random_walk)
        self._start_server = rospy.Service('/stop_random_walk', Empty, self._stop_random_walk)

    def _start_random_walk(self, req):
        self._running = True
        
    def _stop_random_walk(self, req):
        self._running = False
        self._action.cancle_action()
        
    def run(self):
        while not rospy.is_shutdown():
            if self._running:
                for name in names:
                    print 'going to ', name
                    self._action.call_action(name)
                    if self._running:
                        rospy.sleep(10.0)
            else:
                rospy.sleep(1.0)

if __name__ == '__main__':
    rospy.init_node('random_walker')
    
    get_names = topol_map_info()
    
    while not get_names.hasNames():
        rospy.sleep(1.0)
    
    names = get_names.getNames()
    print names
    <commit_msg>fixed service stop<commit_after>#! /usr/bin/env python

import rospy
import sys
# Brings in the SimpleActionClient
import actionlib
import topological_navigation.msg
from strands_navigation_msgs.msg import TopologicalMap
from std_srvs.srv import Empty

class topol_map_info(object):
    def __init__(self) :
        self.sub = rospy.Subscriber("/topological_map", TopologicalMap, self._callback)
        rospy.loginfo(" ... done with subscribing map")
        self._node_names = None

    def _callback(self, msg):
        if self._node_names is None :
            self._node_names = set([n.name for n in msg.nodes])
            self._node_names.remove('ChargingPoint')
                
    def hasNames(self):
        return not self._node_names is None
        
    def getNames(self):
        return self._node_names

class topol_nav_client(object):
    def __init__(self) :
        rospy.on_shutdown(self._on_node_shutdown)
        self.client = actionlib.SimpleActionClient('topological_navigation', topological_navigation.msg.GotoNodeAction)
        self.client.wait_for_server()
        rospy.loginfo(" ... Init done")
        
    def call_action(self, targ):
        navgoal = topological_navigation.msg.GotoNodeGoal()
    
        print "Requesting Navigation to %s" %targ
    
        navgoal.target = targ
        #navgoal.origin = orig
    
        # Sends the goal to the action server.
        self.client.send_goal(navgoal)#,self.done_cb, self.active_cb, self.feedback_cb)
    
        # Waits for the server to finish performing the action.
        self.client.wait_for_result(timeout=rospy.Duration(60.0))
    
        # Prints out the result of executing the action
        ps = self.client.get_result()  # A FibonacciResult
        print ps        

    def cancle_action(self):
        self.client.cancel_all_goals()

    def _on_node_shutdown(self):
        self.client.cancel_all_goals()
        #sleep(2)

class random_walker(object):
    def __init__(self, names) :
        self._running = True
        self._action = topol_nav_client()
        self._names = names
        self._start_server = rospy.Service('/start_random_walk', Empty, self._start_random_walk)
        self._start_server = rospy.Service('/stop_random_walk', Empty, self._stop_random_walk)

    def _start_random_walk(self, req):
        self._running = True
        
    def _stop_random_walk(self, req):
        self._running = False
        self._action.cancle_action()
        
    def run(self):
        while not rospy.is_shutdown():
            for name in names:
                if self._running:           
                    print 'going to ', name
                    self._action.call_action(name)
                    if self._running:
                        rospy.sleep(10.0)
                else:
                    rospy.sleep(1.0)

if __name__ == '__main__':
    rospy.init_node('random_walker')
    
    get_names = topol_map_info()
    
    while not get_names.hasNames():
        rospy.sleep(1.0)
    
    names = get_names.getNames()
    print names
    
{'fraction_non_alphanumeric': 0.08856391718698653, 'fraction_numerical': 0.0031219191587249424, 'mean_word_length': 2.2377659574468085, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2957601', 'n_tokens_mistral': 1896, 'n_tokens_neox': 1829, 'n_words': 394}