class ControllersTests(unittest.TestCase): ''' This is the unittest for the uniscada.controllers module ''' def setUp(self): self.controllers = Controllers() def test_add_controller(self): ''' Test controller add and lookup ''' id1 = self.controllers.find_controller('A') id2 = self.controllers.find_controller('A') id3 = self.controllers.find_controller('B') self.assertTrue(isinstance(id1, Controller)) self.assertTrue(isinstance(id2, Controller)) self.assertTrue(isinstance(id3, Controller)) self.assertEqual(id1, id2) self.assertNotEqual(id1, id3) def test_controller_id_listing(self): ''' Test controller id listing ''' id1 = self.controllers.find_controller('A') id2 = self.controllers.find_controller('B') id3 = self.controllers.find_controller('C') self.assertEqual(sorted(self.controllers.get_id_list()), ['A', 'B', 'C'])
def play(): ( controller_parameters, visual, parameters, history, ) = process_game_parameters() controllers = Controllers( parameters, history, controller_parameters, ) result = Result(parameters, history, controllers) plotting = Plotting( visual, parameters, history, controllers, result, ) animation = Animation( visual, parameters, history, controllers, plotting, result, ) animation.run()
def __init__(self, namespace, arm_name): namespace = '/' + namespace arm_name = '/' + arm_name + '/' self.ctrl = Controllers(namespace, arm_name, rospy.Time.now().to_sec()) prefix = '/motion_ifc/' self.comm_ifc_list = [ MotionCmdCommIfc(prefix + 'interpolate_cp', TransformStamped, self.ctrl, True, 10), MotionCmdCommIfc(prefix + 'interpolate_cr', TransformStamped, self.ctrl, True, 10), MotionCmdCommIfc(prefix + 'interpolate_cv', TransformStamped, self.ctrl, True, 10), MotionCmdCommIfc(prefix + 'interpolate_cf', TransformStamped, self.ctrl, True, 10), MotionCmdCommIfc(prefix + 'interpolate_jp', JointState, self.ctrl, True, 10), MotionCmdCommIfc(prefix + 'interpolate_jr', JointState, self.ctrl, True, 10), MotionCmdCommIfc(prefix + 'interpolate_jv', JointState, self.ctrl, True, 10), MotionCmdCommIfc(prefix + 'interpolate_jf', JointState, self.ctrl, True, 10), MotionCmdCommIfc(prefix + 'servo_cp', TransformStamped, self.ctrl, True, 10), MotionCmdCommIfc(prefix + 'servo_cr', TransformStamped, self.ctrl, True, 10), MotionCmdCommIfc(prefix + 'servo_cv', TransformStamped, self.ctrl, True, 10), MotionCmdCommIfc(prefix + 'servo_cf', TransformStamped, self.ctrl, True, 10), MotionCmdCommIfc(prefix + 'servo_jp', JointState, self.ctrl, True, 10), MotionCmdCommIfc(prefix + 'servo_jr', JointState, self.ctrl, True, 10), MotionCmdCommIfc(prefix + 'servo_jv', JointState, self.ctrl, True, 10), MotionCmdCommIfc(prefix + 'servo_jf', JointState, self.ctrl, True, 10), MotionCmdCommIfc(prefix + 'move_cp', TransformStamped, self.ctrl, True, 10), MotionCmdCommIfc(prefix + 'move_cr', TransformStamped, self.ctrl, True, 10), MotionCmdCommIfc(prefix + 'move_jp', JointState, self.ctrl, True, 10), MotionCmdCommIfc(prefix + 'move_jr', JointState, self.ctrl, True, 10) ]
"""Flask REST API to allow Google Assistant to interface with my apt.""" from flask import Flask from flask import request from controllers import Controllers POWER_ON = ['on', 'true', '1'] POWER_OFF = ['off', 'false', 'none', '0'] DEVICES = ['all', 'tv', 'lights', 'speaker'] app = Flask(__name__) controller = Controllers() # Main Power Endpoint @app.route('/power') def power(): return_msg = "" return_err = "" # Parse query params and call appropriate controller method for device_name, state in request.args.iteritems(): if device_name in DEVICES: device_pwr = getattr(controller, device_name + '_ctrl') if state in POWER_ON: device_pwr(True) return_msg += "[{} power on]".format(device_name) elif state in POWER_OFF: device_pwr() return_msg += "[{} power off]".format(device_name) else: return_err += "[Bad Request '{}={}'] ".format( device_name, state)
def setUp(self): self.controllers = Controllers()
def get(self, request, username, password, fromDate, toDate, node): self.tableStart("GetControllerSummary", username, password) data = Controllers().summary(node, username) return self.tableEnd(request, data)