def init_hardware(): """ Initialize the software representation of the hardware, i.e. Sensors, Proportional Valves, and Discrete Valves The connected Pins are hardcoded here! Return: (list of sensors.DPressureSens): list of software repr of initialized Sensors (list of actuators.Valve): list of software repr of initialized proportional valves (list of actuators.DValve): list of software repr of initialized discrete valves """ print("Initialize Sensors ...") sens = [] sets = [{'name': '0', 'id': 4}, {'name': '1', 'id': 5}, {'name': '2', 'id': 2}, {'name': '3', 'id': 3}, {'name': '4', 'id': 0}, {'name': '5', 'id': 1}, {'name': '6', 'id': 7}, {'name': '7', 'id': 6}] for s in sets: sens.append(sensors.DPressureSens(name=s['name'], mplx_id=s['id'], maxpressure=MAX_PRESSURE)) print('Initialize Valves ...') valve = [] sets = [{'name': '0', 'pin': 'P9_22'}, # Upper Left Leg {'name': '1', 'pin': 'P8_19'}, # Upper Right Leg {'name': '2', 'pin': 'P9_21'}, # Left Belly {'name': '3', 'pin': 'P8_13'}, # Right Belly {'name': '4', 'pin': 'P9_14'}, # Lower Left Leg {'name': '5', 'pin': 'P9_16'}, # Lower Right Leg {'name': '6', 'pin': 'P9_28'}, {'name': '7', 'pin': 'P9_42'}] for elem in sets: valve.append(actuators.Valve(name=elem['name'], pwm_pin=elem['pin'])) dvalve = [] dsets = [{'name': '0', 'pin': 'P8_10'}, # Upper Left Leg {'name': '1', 'pin': 'P8_7'}, # Upper Right Leg {'name': '2', 'pin': 'P8_8'}, # Lower Left Leg {'name': '3', 'pin': 'P8_9'}] # Lower Right Leg] for elem in dsets: dvalve.append(actuators.DiscreteValve( name=elem['name'], pin=elem['pin'])) return sens, valve, dvalve
def init_channels(): """ Initialize the software representation of the hardware, i.e. Sensors, Proportional Valves, and Discrete Valves """ rootLogger.info("Initialize IMUs ...") # mplx address for IMU is 0x71 imu_set = [imu for imu in IMUset] imu_used_ = [CHANNELset[name]['IMUs'] for name in CHANNELset] while [None] in imu_used_: imu_used_.remove([None]) imu_used = list(np.unique([imu for subl in imu_used_ for imu in subl])) for imu in imu_used: if imu not in imu_set and imu is not None: raise KeyError( 'IMU with name "{}"'.format(imu) + ' is used for angle' + 'calculation, but is not in the set of connected IMUs') try: IMU = {} for name in IMUset: IMU[name] = sensors.MPU_9150(name=name, mplx_id=IMUset[name]['id']) except IOError: # not connected IMU = False rootLogger.info("IMU detected?: {}".format(not (not (IMU)))) rootLogger.info("Initialize Channels ...") PSens, PValve, DValve, Controller, Imu_controller = {}, {}, {}, {}, {} for name in CHANNELset: PSens[name] = sensors.DPressureSens( name=name, mplx_id=CHANNELset[name]['PSensid'], maxpressure=MAX_PRESSURE) PValve[name] = actuators.Valve(name=name, pwm_pin=CHANNELset[name]['pin']) Controller[name] = ctrlib.PidController(CHANNELset[name]['ctr'], TSAMPLING, MAX_CTROUT) if CHANNELset[name]['IMUs'][-1]: Imu_controller[name] = ctrlib.PidController( CHANNELset[name]['ctrIMU'], TSAMPLING, MAX_CTROUT) for name in DiscreteCHANNELset: DValve[name] = actuators.DiscreteValve( name=name, pin=DiscreteCHANNELset[name]['pin']) return PSens, PValve, DValve, IMU, Controller, Imu_controller
def init_hardware(): """ Initialize the software representation of the hardware, i.e. Sensors, Proportional Valves, and Discrete Valves The connected Pins are hardcoded here! Return: (list of sensors.DPressureSens): list of software repr of initialized Sensors (list of actuators.Valve): list of software repr of initialized proportional valves (list of actuators.DValve): list of software repr of initialized discrete valves """ rootLogger.info("Initialize IMUs ...") # mplx address for IMU is 0x71 IMU = [] sets = [{'name': '0', 'id': 0}, #{'name': '1', 'id': 1}, {'name': '2', 'id': 2}, {'name': '3', 'id': 3}, #{'name': '4', 'id': 4}, {'name': '5', 'id': 5}] try: for s in sets: IMU.append(sensors.MPU_9150(name=s['name'], mplx_id=s['id'])) except IOError: # not connected IMU = False rootLogger.info("IMU detected?: {}".format(not(not(IMU)))) rootLogger.info("Initialize Pressure Sensors ...") sens = [] sets = [{'name': '0', 'id': 4}, {'name': '1', 'id': 5}, {'name': '2', 'id': 2}, {'name': '3', 'id': 3}, {'name': '4', 'id': 0}, {'name': '5', 'id': 1}, {'name': '6', 'id': 7}, {'name': '7', 'id': 6}] for s in sets: sens.append(sensors.DPressureSens(name=s['name'], mplx_id=s['id'], maxpressure=MAX_PRESSURE)) rootLogger.info('Initialize Valves ...') valve = [] sets = [{'name': '0', 'pin': 'P9_22'}, # Upper Left Leg {'name': '1', 'pin': 'P8_19'}, # Upper Right Leg {'name': '2', 'pin': 'P9_21'}, # Left Belly {'name': '3', 'pin': 'P8_13'}, # Right Belly {'name': '4', 'pin': 'P9_14'}, # Lower Left Leg {'name': '5', 'pin': 'P9_16'}, # Lower Right Leg {'name': '6', 'pin': 'P9_28'}, {'name': '7', 'pin': 'P9_42'}] for elem in sets: valve.append(actuators.Valve(name=elem['name'], pwm_pin=elem['pin'])) dvalve = [] dsets = [{'name': '0', 'pin': 'P8_10'}, # Upper Left Leg {'name': '1', 'pin': 'P8_7'}, # Upper Right Leg {'name': '2', 'pin': 'P8_8'}, # Lower Left Leg {'name': '3', 'pin': 'P8_9'}] # Lower Right Leg] for elem in dsets: dvalve.append(actuators.DiscreteValve( name=elem['name'], pin=elem['pin'])) return sens, valve, dvalve, IMU