def fingerControl(self, finger, motorDir): # TODO - TODO - While needs an output condition? logging.info("IOUTILS::fingerControl") """ With these three lines of code, the control of a single motor is achieved. First the feedback value of the controller is obtained from a specific channel of the ADC IC. Then, the control signal is computed with a PID. Finally, the control signal is applied to the motor as a PWM signal generated by the PWM IC. """ # Initialize PID pid = PID(PID_KP, PID_KI, PID_KD) pid.setWindup = MOTOR_CTRL_MAX pid.setSampleTime = 0.2 pid.SetPoint = 800 # Initialize buses # Re-init will be necessary? # self.adc = MCP3008.MCP3008(clk=CLK, cs=CS, miso=MISO, mosi=MOSI) # Initialize PWM # Re-init will be necessary? #self.pwm = PCA9685.PCA9685(PCA_I2C_ADDR) #self.pwm.set_pwm_freq(PWM_FRQUENCY) logging.debug("IOUTILS::fingerControl - Reading from ADC Channel [%i]", FINGER_CHANNELS_MATRIX[ADC][finger]) while True: feedback = self.getPotentiometerValue(finger) pid.update(feedback) duty_cycle = int(pid.output) self.motor_control(duty_cycle, finger, motorDir)
} sim = Simulator() tank1 = Tank('Tank1') sim.add(tank1) tank1.set_values(tank1_values) return sim pid_t = PID(P=40.0, I=1.0, D=0.5) pid_t.set_sample_time(10) pid_t.set_windup(50.0) pid_t.SetPoint = 30.0 pid_s = PID(P=0.8, I=0.05, D=0.1) pid_s.set_sample_time(5) pid_t.set_windup(20) pid_s.SetPoint = 1.0 def get_settings(ts, values): pid_t.update(values['Tank1_o_t'], ts) pid_s.update(values['Tank1_o_s'] / 10.0, ts) i = pid_t.output if i > 80: i = 80 if i < 0: