def __init__(self): Resource.__init__(self) self.policy = Policy.UNIQUE self.register_name("DeployableCamera") dg.print("Deployable camera motors settings:") servo1_pin = cfg.motor_config.get_pin("DeployableCamera", "Servo1") self.servo1_lim_upper = cfg.motor_config.get_limit( "DeployableCamera", "Servo1", "Upper") self.servo1_lim_lower = cfg.motor_config.get_limit( "DeployableCamera", "Servo1", "Lower") servo2_pin = cfg.motor_config.get_pin("DeployableCamera", "Servo2") self.servo2_lim_upper = cfg.motor_config.get_limit( "DeployableCamera", "Servo2", "Upper") self.servo2_lim_lower = cfg.motor_config.get_limit( "DeployableCamera", "Servo2", "Lower") servo3_pin = cfg.motor_config.get_pin("DeployableCamera", "Servo3") self.servo3_lim_upper = cfg.motor_config.get_limit( "DeployableCamera", "Servo3", "Upper") self.servo3_lim_lower = cfg.motor_config.get_limit( "DeployableCamera", "Servo3", "Lower") dg.print(" Servo 1 pin: {}".format(servo1_pin)) dg.print(" Servo 1 upper limit: {}".format(self.servo1_lim_upper)) dg.print(" Servo 1 lower limit: {}".format(self.servo1_lim_lower)) dg.print(" Servo 2 pin: {}".format(servo2_pin)) dg.print(" Servo 2 upper limit: {}".format(self.servo2_lim_upper)) dg.print(" Servo 2 lower limit: {}".format(self.servo2_lim_lower)) dg.print(" Servo 3 pin: {}".format(servo3_pin)) dg.print(" Servo 3 upper limit: {}".format(self.servo3_lim_upper)) dg.print(" Servo 3 lower limit: {}".format(self.servo3_lim_lower))
def __init__(self): Resource.__init__(self) self.policy = Policy.UNIQUE self.register_name("Wheels") left_pwm_pin = cfg.motor_config.get_pwm_pin("Wheels", "Left") left_digital_pin = cfg.motor_config.get_digital_pin("Wheels", "Left") right_pwm_pin = cfg.motor_config.get_pwm_pin("Wheels", "Right") right_digital_pin = cfg.motor_config.get_digital_pin("Wheels", "Right") self._ymax = 100 self._xmax = 100 self.leftmotor_in1_pin = left_digital_pin self.rightmotor_in1_pin = right_digital_pin self.PWM_left = left_pwm_pin self.PWM_right = right_pwm_pin io.setmode(io.BCM) io.setup(self.leftmotor_in1_pin, io.OUT) io.setup(self.rightmotor_in1_pin, io.OUT) io.output(self.leftmotor_in1_pin, False) io.output(self.rightmotor_in1_pin, False) io.setwarnings(False) self.duty_cycle = 4095 self.PCA9685_pwm = PCA9685_motor.PCA9685() self.PCA9685_pwm.set_pwm_freq(60)
def __init__(self): Resource.__init__(self) self.policy = Policy.UNIQUE self.register_name("DeployableCamera") self.i2c = busio.I2C(board.SCL, board.SDA) self.servo = adafruit_pca9685.PCA9685(self.i2c) self.kit = ServoKit(channels=16) servo1_pin = cfg.motor_config.get_pin("DeployableCamera", "Servo1") self.servo1_lim_upper = cfg.motor_config.get_limit( "DeployableCamera", "Servo1", "Upper") self.servo1_lim_lower = cfg.motor_config.get_limit( "DeployableCamera", "Servo1", "Lower") servo2_pin = cfg.motor_config.get_pin("DeployableCamera", "Servo2") self.servo2_lim_upper = cfg.motor_config.get_limit( "DeployableCamera", "Servo2", "Upper") self.servo2_lim_lower = cfg.motor_config.get_limit( "DeployableCamera", "Servo2", "Lower") servo3_pin = cfg.motor_config.get_pin("DeployableCamera", "Servo3") self.servo3_lim_upper = cfg.motor_config.get_limit( "DeployableCamera", "Servo3", "Upper") self.servo3_lim_lower = cfg.motor_config.get_limit( "DeployableCamera", "Servo3", "Lower") self.servo_top = self.kit.servo[servo1_pin] self.servo_middle = self.kit.servo[servo2_pin] self.servo_bottom = self.kit.servo[servo3_pin] self.servo_top.actuation_range = 360 self.servo_middle.actuation_range = 360 self.servo_bottom.actuation_range = 360 self.servo_top.set_pulse_width_range(500, 3250) self.servo_middle.set_pulse_width_range(500, 3250) self.servo_bottom.set_pulse_width_range(500, 3250)
def __init__(self): Resource.__init__(self) self.policy = Policy.SHARED self.register_name("Ultrasound") try: self.trigger_pin = cfg.auto_config.ultrasound_trigger_pin() self.echo_pin = cfg.auto_config.ultrasound_echo_pin() except cfg.ConfigurationError as e: raise ResourceRawError(str(e)) self.active = False self.distance = -1 self.lock = RWLock()
def __init__(self): Resource.__init__(self) self.policy = Policy.UNIQUE self.register_name("Arm") dg.print("Mock arm motors settings:") servo1_pin = cfg.motor_config.get_pin("Arm", "Servo1") servo2_pin = cfg.motor_config.get_pin("Arm", "Servo2") servo3_pin = cfg.motor_config.get_pin("Arm", "Servo3") gripper_pin = cfg.motor_config.get_pin("Arm", "Gripper") dg.print(" Servo 1 pin: {}".format(servo1_pin)) dg.print(" Servo 2 pin: {}".format(servo2_pin)) dg.print(" Servo 3 pin: {}".format(servo3_pin)) dg.print(" Gripper pin: {}".format(gripper_pin))
def fin(): """ Remove test namespaces """ for pod in config.PRIVILEGED_PODS: pod_object = Pod(name=pod, namespace=config.NETWORK_NS) pod_container = pod_object.containers()[0].name for bridge in config.ALL_BRIDGES: pod_object.run_command( command=config.OVS_VSCTL_DEL_BR.format(bridge=bridge), container=pod_container) if config.BOND_SUPPORT_ENV: pod_object.run_command(command=config.IP_LINK_DEL_BOND, container=pod_container) for vm in vms: vm_object = VirtualMachine(name=vm, namespace=config.NETWORK_NS) if vm_object.get(): vm_object.delete(wait=True) utils.run_command(command=config.SVC_DELETE_CMD) for yaml_ in (config.PRIVILEGED_DAEMONSET_YAML, config.OVS_VLAN_YAML, config.OVS_BOND_YAML): Resource().delete(yaml_file=yaml_, wait=True)
def setUp(self): # Try to instantiate a Resource object test = False try: Resource() except NotImplementedError: test = True self.assertTrue(test)
def __init__(self): Resource.__init__(self) self.policy = Policy.UNIQUE self.register_name("Wheels") self._ymax = 100 self._xmax = 100 self.duty_cycle = 4095 dg.print("Mock wheel motors settings:") left_pwm_pin = cfg.motor_config.get_pwm_pin("Wheels", "Left") left_digital_pin = cfg.motor_config.get_digital_pin("Wheels", "Left") right_pwm_pin = cfg.motor_config.get_pwm_pin("Wheels", "Right") right_digital_pin = cfg.motor_config.get_digital_pin("Wheels", "Right") dg.print(" Left PWM pin: {}".format(left_pwm_pin)) dg.print(" Left digital pin: {}".format(left_digital_pin)) dg.print(" Right PWM pin: {}".format(right_pwm_pin)) dg.print(" Right digital pin: {}".format(right_digital_pin))
def __init__(self): '''Register name and access policy. Obtain settings from CameraConfiguration. Initialise members.''' Resource.__init__(self) self.policy = Policy.SHARED self.register_name("Camera") try: self.source = cfg.cam_config.device() # gstreamer device name self.framerate = cfg.cam_config.capture_framerate() self.frame_width = cfg.cam_config.capture_frame_width() self.frame_height = cfg.cam_config.capture_frame_height() except cfg.ConfigurationError as e: raise ResourceRawError(str(e)) self.gst_comm = None # string corresponding to gstreamer pipe self.cap = None # opencv capture object self.active = False self.camlock = RWLock() # allow multiple readers, single writer self.frame = np.zeros(3) # current camera frame
def __init__(self): """ Call set_values to set angles ofs servos. Will need to callibrate for limits """ Resource.__init__(self) self.policy = Policy.UNIQUE self.register_name("Arm") self.i2c = busio.I2C(board.SCL, board.SDA) # self.servo = PCA9685_servo.PCA9685(self.i2c) self.servo = adafruit_pca9685.PCA9685(self.i2c) self.kit = ServoKit(channels=16) gripper_pin = cfg.motor_config.get_pin("Arm", "Gripper") servo1_pin = cfg.motor_config.get_pin("Arm", "Servo1") servo2_pin = cfg.motor_config.get_pin("Arm", "Servo2") servo3_pin = cfg.motor_config.get_pin("Arm", "Servo3") #servo1_pwm_pin = cfg.motor_config.get_pwm_pin("Arm", "Servo1") #servo1_digital_pin = cfg.motor_config.get_digital_pin("Arm", "Servo1") #servo2_pwm_pin = cfg.motor_config.get_pwm_pin("Arm", "Servo2") #servo2_digital_pin = cfg.motor_config.get_digital_pin("Arm", "Servo2") #servo3_pwm_pin = cfg.motor_config.get_pwm_pin("Arm", "Servo3") #servo3_digital_pin = cfg.motor_config.get_digital_pin("Arm", "Servo3") #gripper_pwm_pin = cfg.motor_config.get_pwm_pin("Arm", "Gripper") #gripper_digital_pin = cfg.motor_config.get_digital_pin("Arm", "Gripper") # 3 Servos, defines PIN numbers self.servo_grab = self.kit.servo[gripper_pin] self.servo_top = self.kit.servo[servo1_pin] self.servo_middle = self.kit.servo[servo2_pin] self.servo_bottom = self.kit.servo[servo3_pin] self.servo_grab.actuation_range = 360 self.servo_top.actuation_range = 360 self.servo_middle.actuation_range = 360 self.servo_bottom.actuation_range = 360 # Callibrated to Proper Servo values. self.servo_grab.set_pulse_width_range(500, 3250) self.servo_top.set_pulse_width_range(500, 3250) self.servo_middle.set_pulse_width_range(500, 3250) self.servo_bottom.set_pulse_width_range(500, 3250)
def __init__(self, json_path): self.trains = {} self.routes = {} self.resources = {} self.data = None with open(json_path) as f: data = json.load(f) self.data = data self.label = data["label"] self.hash = data["hash"] for d in data["resources"]: self.add_resource(Resource(data=d)) routes = {} for d in data["routes"]: routes[d["id"]] = d for d in data["service_intentions"]: train = self.add_train(Train(data=d)) train.network.add_route( Route(data=routes[train.get_id()], train=train))
def prepare_env(request): nodes_network_info = {} bond_name = config.BOND_NAME bond_bridge = config.BOND_BRIDGE bridge_name_vxlan = config.BRIDGE_NAME_VXLAN bridge_name_real_nics = config.BRIDGE_NAME_REAL_NICS vxlan_port = config.OVS_NO_VLAN_PORT vms = config.VMS_LIST active_node_nics = {} def fin(): """ Remove test namespaces """ for pod in config.PRIVILEGED_PODS: pod_object = Pod(name=pod, namespace=config.NETWORK_NS) pod_container = pod_object.containers()[0].name for bridge in config.ALL_BRIDGES: pod_object.run_command( command=config.OVS_VSCTL_DEL_BR.format(bridge=bridge), container=pod_container) if config.BOND_SUPPORT_ENV: pod_object.run_command(command=config.IP_LINK_DEL_BOND, container=pod_container) for vm in vms: vm_object = VirtualMachine(name=vm, namespace=config.NETWORK_NS) if vm_object.get(): vm_object.delete(wait=True) utils.run_command(command=config.SVC_DELETE_CMD) for yaml_ in (config.PRIVILEGED_DAEMONSET_YAML, config.OVS_VLAN_YAML, config.OVS_BOND_YAML): Resource().delete(yaml_file=yaml_, wait=True) request.addfinalizer(fin) compute_nodes = Node().list( get_names=True, label_selector="node-role.kubernetes.io/compute=true") assert utils.run_command(command=config.SVC_CMD)[0] assert utils.run_command(command=config.ADM_CMD)[0] assert Resource().create(yaml_file=config.PRIVILEGED_DAEMONSET_YAML) wait_for_pods_to_match_compute_nodes_number( number_of_nodes=len(compute_nodes)) config.PRIVILEGED_PODS = Pod().list( get_names=True, label_selector="app=privileged-test-pod") assert Resource().create(yaml_file=config.OVS_VLAN_YAML) assert Resource().create(yaml_file=config.OVS_BOND_YAML) for node in compute_nodes: node_obj = Node(name=node, namespace=config.NETWORK_NS) node_info = node_obj.get() for addr in node_info.status.addresses: if addr.type == "InternalIP": nodes_network_info[node] = addr.address break # Check if we running with real NICs (not on VM) # Check the number of the NICs on the node to ser BOND support for idx, pod in enumerate(config.PRIVILEGED_PODS): pod_object = Pod(name=pod, namespace=config.NETWORK_NS) pod_container = pod_object.containers()[0].name active_node_nics[pod] = [] assert pod_object.wait_for_status(status=types.RUNNING) err, nics = pod_object.run_command(command=config.GET_NICS_CMD, container=pod_container) assert err nics = nics.splitlines() err, default_gw = pod_object.run_command( command=config.GET_DEFAULT_GW_CMD, container=pod_container) assert err for nic in nics: err, nic_state = pod_object.run_command( command=config.GET_NIC_STATE_CMD.format(nic=nic), container=pod_container) assert err if nic_state.strip() == "up": if nic in [ i for i in default_gw.splitlines() if 'default' in i ][0]: continue active_node_nics[pod].append(nic) err, driver = pod_object.run_command( command=config.CHECK_NIC_DRIVER_CMD.format(nic=nic), container=pod_container) assert err config.REAL_NICS_ENV = driver.strip() != "virtio_net" config.BOND_SUPPORT_ENV = len(active_node_nics[pod]) > 3 # Configure bridges on the nodes for idx, pod in enumerate(config.PRIVILEGED_PODS): pod_object = Pod(name=pod, namespace=config.NETWORK_NS) pod_name = pod node_name = pod_object.node() pod_container = pod_object.containers()[0].name if config.REAL_NICS_ENV: assert pod_object.run_command( command=config.OVS_VSCTL_ADD_BR.format( bridge=bridge_name_real_nics), container=pod_container)[0] config.CREATED_BRIDGES.add(bridge_name_real_nics) assert pod_object.run_command( command=config.OVS_VSCTL_ADD_PORT.format( bridge=bridge_name_real_nics, interface=active_node_nics[pod_name][0]), container=pod_container)[0] else: assert pod_object.run_command( command=config.OVS_VSCTL_ADD_BR.format( bridge=bridge_name_vxlan), container=pod_container)[0] config.CREATED_BRIDGES.add(bridge_name_vxlan) for name, ip in nodes_network_info.items(): if name != node_name: assert pod_object.run_command( command=config.OVS_VSCTL_ADD_VXLAN.format( bridge=bridge_name_vxlan, ip=ip), container=pod_container)[0] break assert pod_object.run_command( command=config.OVS_VSCTL_ADD_PORT_VXLAN.format( bridge=config.BRIDGE_NAME_VXLAN, port_1=vxlan_port, port_2=vxlan_port), container=pod_container)[0] assert pod_object.run_command(command=config.IP_ADDR_ADD.format( ip=config.OVS_NODES_IPS[idx], dev=vxlan_port), container=pod_container)[0] # Configure bridge on BOND if env support BOND if config.BOND_SUPPORT_ENV: bond_commands = [ config.IP_LINK_ADD_BOND, config.IP_LINK_SET_BOND_PARAMS ] for pod in config.PRIVILEGED_PODS: pod_object = Pod(name=pod, namespace=config.NETWORK_NS) pod_name = pod pod_container = pod_object.containers()[0].name for cmd in bond_commands: assert pod_object.run_command(command=cmd, container=pod_container)[0] for nic in active_node_nics[pod_name][1:3]: assert pod_object.run_command( command=config.IP_LINK_INTERFACE_DOWN.format( interface=nic), container=pod_container)[0] assert pod_object.run_command( command=config.IP_LINK_SET_INTERFACE_MASTER.format( interface=nic, bond=bond_name), container=pod_container)[0] assert pod_object.run_command( command=config.IP_LINK_INTERFACE_UP.format(interface=nic), container=pod_container)[0] assert pod_object.run_command( command=config.IP_LINK_INTERFACE_UP.format( interface=bond_name), container=pod_container)[0] res, out = pod_object.run_command( command=config.IP_LINK_SHOW.format(interface=bond_name), container=pod_container) assert res assert "state UP" in out assert pod_object.run_command( command=config.OVS_VSCTL_ADD_BR.format(bridge=bond_bridge), container=pod_container)[0] config.CREATED_BRIDGES.add(bond_bridge) assert pod_object.run_command( command=config.OVS_VSCTL_ADD_PORT.format(bridge=bond_bridge, interface=bond_name), container=pod_container)[0] for vm in vms: vm_object = VirtualMachine(name=vm, namespace=config.NETWORK_NS) json_out = utils.get_json_from_template(file_=config.VM_YAML_TEMPLATE, NAME=vm, MULTUS_NETWORK="ovs-vlan-net") spec = json_out.get('spec').get('template').get('spec') volumes = spec.get('volumes') cloud_init = [i for i in volumes if 'cloudInitNoCloud' in i][0] cloud_init_data = volumes.pop(volumes.index(cloud_init)) cloud_init_user_data = cloud_init_data.get('cloudInitNoCloud').get( 'userData') cloud_init_user_data += ( "\nruncmd:\n" " - nmcli con add type ethernet con-name eth1 ifname eth1\n" " - nmcli con mod eth1 ipv4.addresses {ip}/24 ipv4.method manual\n" " - systemctl start qemu-guest-agent\n".format( ip=config.VMS.get(vm).get("ovs_ip"))) if not config.REAL_NICS_ENV: cloud_init_user_data += " - ip link set mtu 1450 eth1\n" if config.BOND_SUPPORT_ENV: interfaces = spec.get('domain').get('devices').get('interfaces') networks = spec.get('networks') bond_bridge_interface = {'bridge': {}, 'name': 'ovs-net-bond'} bond_bridge_network = { 'multus': { 'networkName': 'ovs-net-bond' }, 'name': 'ovs-net-bond' } interfaces.append(bond_bridge_interface) networks.append(bond_bridge_network) cloud_init_user_data += ( " - nmcli con add type ethernet con-name eth1 ifname eth2\n" " - nmcli con mod eth2 ipv4.addresses {ip}/24 ipv4.method manual\n" .format(ip=config.VMS.get(vm).get("bond_ip"))) spec['domain']['devices']['interfaces'] = interfaces spec['networks'] = networks cloud_init_data['cloudInitNoCloud']['userData'] = cloud_init_user_data volumes.append(cloud_init_data) spec['volumes'] = volumes json_out['spec']['template']['spec'] = spec assert vm_object.create(resource_dict=json_out, wait=True) for vmi in vms: vmi_object = VirtualMachineInstance(name=vmi, namespace=config.NETWORK_NS) assert vmi_object.wait_for_status(status=types.RUNNING) wait_for_vm_interfaces(vmi=vmi_object) vmi_data = vmi_object.get() ifcs = vmi_data.get('status', {}).get('interfaces', []) active_ifcs = [ i.get('ipAddress') for i in ifcs if i.get('interfaceName') == "eth0" ] config.VMS[vmi]["pod_ip"] = active_ifcs[0].split("/")[0]
def __init__(self): Resource.__init__(self) self.policy = Policy.SHARED self.register_name("IPCamera") self.host = None self.port = 5520
def test_init(self): Resource.__call__(self)