<commit_before>import roslib; roslib.load_manifest('pycontroller_manager')
import rospy
import pr2_mechanism_msgs.srv as pmm

class ControllerManager:

    def __init__(self):
        # LoadController        
        self.load = rospy.ServiceProxy('pr2_controller_manager/load_controller', pmm.LoadController)

        # UnloadController        
        self.unload = rospy.ServiceProxy('pr2_controller_manager/unload_controller', pmm.UnloadController)

        # SwitchController
        self._switch_controller = rospy.ServiceProxy('pr2_controller_manager/switch_controller', pmm.SwitchController)

        self.list_controllers = rospy.ServiceProxy('pr2_controller_manager/list_controllers', pmm.ListControllers)

        self.joint_controllers = {}
        self.cart_controllers = {}
        for arm in ['l', 'r']:
            self.joint_controllers[arm] = arm + '_arm_controller'
            self.cart_controllers[arm] = cart_controller_name = arm + '_cart'

    def switch(self, start_con, stop_con):
        con = self.list_controllers()
        valid_start = []
        valid_stop = []

        #Add the ones that are loaded but not running.
        for idx, controller in enumerate(con.controllers):
            if controller in start_con:
                #print 'found', controller, 'it\'s state is', con.state[idx], len(con.state[idx]), con.state[idx].__class__
                if con.state[idx] != 'running':<commit_msg>Added potential fix to pycontroller_manager to resolve the controller stopping problem.<commit_after>import roslib; roslib.load_manifest('pycontroller_manager')
import rospy
import pr2_mechanism_msgs.srv as pmm

POSSIBLE_CTRLS_PARAMETER = "/pr2_controller_manager/%s_arm_possible_ctrls" # KelseyH

class ControllerManager:

    def __init__(self):
        # LoadController        
        self.load = rospy.ServiceProxy('pr2_controller_manager/load_controller', pmm.LoadController)

        # UnloadController        
        self.unload = rospy.ServiceProxy('pr2_controller_manager/unload_controller', pmm.UnloadController)

        # SwitchController
        self._switch_controller = rospy.ServiceProxy('pr2_controller_manager/switch_controller', pmm.SwitchController)

        self.list_controllers = rospy.ServiceProxy('pr2_controller_manager/list_controllers', pmm.ListControllers)

        self.joint_controllers = {}
        self.cart_controllers = {}
        for arm in ['l', 'r']:
            self.joint_controllers[arm] = arm + '_arm_controller'
            self.cart_controllers[arm] = cart_controller_name = arm + '_cart'

    ##
    # Given the list of starting controllers, look for the possible arm controllers which
    # conflict with those which are currently running.
    # KelseyH
    def get_possible_running_ctrls(self, start_con):
        # find the sides the start controllers are on
        arms_starting = []
        for con in start_con:
            for arm in ['l', 'r']:
                if con == self.joint_controllers[arm] or con == self.cart_controllers[arm]:
                    arms_starting.append(arm)

        # find the possible controllers running corresponding to those sides
        possible_ctrls = []
        for arm in ['l', 'r']:
            if arm in arms_starting:
                possible_ctrls.append(rosparam.get_param(POSSIBLE_CTRLS_PARAMETER % arm))

        # check to see if the possible controllers are indeed running
        stop_con = []
        con_states = self.list_controllers()
        for i, controller in enumerate(con_states.controllers):
            if controller in possible_ctrls and con_states.state[i] == 'running':
                stop_con.append(controller)
        return stop_con

    def switch(self, start_con, stop_con):
        stop_con.extend(self.get_possible_running_ctrls(start_con)) # KelseyH
        con = self.list_controllers()
        valid_start = []
        valid_stop = []

        #Add the ones that are loaded but not running.
        for idx, controller in enumerate(con.controllers):
            if controller in start_con:
                #print 'found', controller, 'it\'s state is', con.state[idx], len(con.state[idx]), con.state[idx].__class__
                if con.state[idx] != 'running':
{'fraction_non_alphanumeric': 0.09071530080530554, 'fraction_numerical': 0.0026054002842254855, 'mean_word_length': 2.9174397031539887, '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': '139852', 'n_tokens_mistral': 1226, 'n_tokens_neox': 1194, 'n_words': 272}