make slightly resilient to missing sensors

This commit is contained in:
Nicolò Balzarotti 2022-11-19 19:20:04 +01:00
parent c817430c6d
commit f216ebd6db
2 changed files with 5 additions and 1 deletions

View File

@ -39,7 +39,7 @@ class FixedDutyCycle(controllers.Controller):
def fixed_duty_wrapper(args): def fixed_duty_wrapper(args):
name, duty, period = stringify(args.car, quote=False), args.cdr.car, args.cdr.cdr.car name, duty, period = stringify(args.car, quote=False), args.cdr.car, args.cdr.cdr.car
print('name, duty, period', name, duty, period) print('name, duty, period', name, duty*100, period)
return (name, FixedDutyCycle( return (name, FixedDutyCycle(
target=None, # reach_period_s=60*60, target=None, # reach_period_s=60*60,
duty_perc=duty*100, period=period, duty_perc=duty*100, period=period,

View File

@ -126,9 +126,13 @@ class State():
for sensor in self.envdata.get('sensors', ()): for sensor in self.envdata.get('sensors', ()):
_, ctrl, target = self.envdata['sensors'][sensor] _, ctrl, target = self.envdata['sensors'][sensor]
self.envdata['sensors'][sensor] = (get_sensor_value(sensor), ctrl, target) self.envdata['sensors'][sensor] = (get_sensor_value(sensor), ctrl, target)
print(self.envdata)
# Apply actuators # Apply actuators
for controller in self.envdata.get('controllers', {}).keys(): for controller in self.envdata.get('controllers', {}).keys():
ctrl = self.envdata['controllers'][controller] ctrl = self.envdata['controllers'][controller]
if ctrl.input_label not in self.envdata['sensors'].keys():
print(f'Missing sensor {ctrl.input_label}')
continue
response = ctrl.apply(self.envdata['sensors'][ctrl.input_label][0]) response = ctrl.apply(self.envdata['sensors'][ctrl.input_label][0])
if self.check(): if self.check():
if self.next() is None: if self.next() is None: