def __init__(self, config): self._motors = Motors(config) self._sensors = Sensors(config) def left_speed(): return self._sensors.speed_left def right_speed(): return self._sensors.speed_right def left_ticks(): return self._sensors.enc_ticks_left def right_ticks(): return self._sensors.enc_ticks_right self._left = Helper(speed_sensor=left_speed, ticks_sensor=left_ticks) self._right = Helper(speed_sensor=right_speed, ticks_sensor=right_ticks)
def __init__(self, config): self._motors = Motors(config) self._sensors = Sensors(config) def left_speed(): return self._sensors.speed_left def right_speed(): return self._sensors.speed_right def left_ticks(): return self._sensors.enc_ticks_left def right_ticks(): return self._sensors.enc_ticks_left self._left = Helper(speed_sensor=left_speed, ticks_sensor=left_ticks) self._right = Helper(speed_sensor=right_speed, ticks_sensor=right_ticks)
class BotController(object): """ This controller uses PID in a closed-loop to stabilise bot speed regardless of surface it is on (hard, carpet, asphalt). It also presents signed ticks and signed speed readings to the user, courtesy of Helper class (see below). This class expects that its on_timer() method is called at 100Hz frequency. """ def __init__(self, config): self._motors = Motors(config) self._sensors = Sensors(config) def left_speed(): return self._sensors.speed_left def right_speed(): return self._sensors.speed_right def left_ticks(): return self._sensors.enc_ticks_left def right_ticks(): return self._sensors.enc_ticks_left self._left = Helper(speed_sensor=left_speed, ticks_sensor=left_ticks) self._right = Helper(speed_sensor=right_speed, ticks_sensor=right_ticks) def start(self): self._sensors.start() def stop(self): self._motors.run(0, 0) self._motors.close() self._sensors.stop() def on_timer(self): self._sensors.read() self._left.on_timer() self._right.on_timer() self._motors.run(self._left.torque, self._right.torque) def run(self, speed_left, speed_right): self._left.run(speed_left) self._right.run(speed_right) @property def ticks(self): return self._left.ticks, self._right.ticks @property def actual_speed(self): return self._left.speed, self._right.speed @property def timer(self): return self._sensors.timer @property def values(self): return self._sensors.values
class BotController(object): """ This controller uses PID in a closed-loop to stabilise bot speed regardless of surface it is on (hard, carpet, asphalt). It also presents signed ticks and signed speed readings to the user, courtesy of Helper class (see below). This class expects that its on_timer() method is called at 100Hz frequency. """ def __init__(self, config): self._motors = Motors(config) self._sensors = Sensors(config) def left_speed(): return self._sensors.speed_left def right_speed(): return self._sensors.speed_right def left_ticks(): return self._sensors.enc_ticks_left def right_ticks(): return self._sensors.enc_ticks_right self._left = Helper(speed_sensor=left_speed, ticks_sensor=left_ticks) self._right = Helper(speed_sensor=right_speed, ticks_sensor=right_ticks) def start(self): self._sensors.start() def stop(self): self._motors.run(0, 0) self._motors.close() self._sensors.stop() def on_timer(self): self._sensors.read() self._left.on_timer() self._right.on_timer() self._motors.run(self._left.torque, self._right.torque) def run(self, speed_left, speed_right): self._left.run(speed_left) self._right.run(speed_right) @property def ticks(self): return self._left.ticks, self._right.ticks @property def actual_speed(self): return self._left.speed, self._right.speed @property def timer(self): return self._sensors.timer @property def values(self): return self._sensors.values
import beaglebone_pru_adc as adc import time import config from robot.motor import Motors if __name__ == '__main__': adc = adc.Capture() adc.encoder0_pin = config.MOTOR_LEFT['encoder_pin'] adc.encoder1_pin = config.MOTOR_RIGHT['encoder_pin'] adc.encoder0_threshold = 4096 adc.encoder1_threshold = 4096 motors = Motors(config) adc.start() motors.run(60, 60) time.sleep(2.0) motors.run(0, 0) adc.stop() adc.wait() _, min0, max0, _, _ = adc.encoder0_values _, min1, max1, _, _ = adc.encoder1_values adc.close() print 'Left encoder measured range:', min0, max0, 'Recommended threshold:', int(0.9 * (max0-min0)) print 'Right encoder measured range:', min1, max1, 'Recommended threshold:', int(0.9 * (max1-min1))
from robot.motor import Motors from robot.sensors import Sensors import config import time if __name__ == '__main__': SPEED = 40 motors = Motors(config) sensors = Sensors(config) sensors.start() torque = 0 data = [] for _ in range(300): time.sleep(0.01) sensors.read() data.append((sensors.timer, sensors.speed_left, sensors.speed_right, sensors.enc_ticks_left, sensors.enc_ticks_right, torque)) if _ == 50: torque = SPEED motors.run(SPEED, SPEED)
from robot.motor import Motors from robot.sensors import Sensors import config import time if __name__ == '__main__': SPEED = 40 motors = Motors(config) sensors = Sensors(config) sensors.start() torque = 0 data = [] for _ in range(300): time.sleep(0.01) sensors.read() data.append((sensors.timer, sensors.speed_left, sensors.speed_right, sensors.enc_ticks_left, sensors.enc_ticks_right, torque)) if _ == 50: torque = SPEED motors.run(SPEED, SPEED) if _ == 150: torque = -SPEED motors.run(-SPEED, -SPEED)
import beaglebone_pru_adc as adc import time import config from robot.motor import Motors if __name__ == '__main__': adc = adc.Capture() adc.encoder0_pin = config.MOTOR_LEFT['encoder_pin'] adc.encoder1_pin = config.MOTOR_RIGHT['encoder_pin'] adc.encoder0_threshold = 4096 adc.encoder1_threshold = 4096 motors = Motors(config) adc.start() motors.run(60, 60) time.sleep(2.0) motors.run(0, 0) adc.stop() adc.wait() _, min0, max0, _, _ = adc.encoder0_values _, min1, max1, _, _ = adc.encoder1_values adc.close() print 'Left encoder measured range:', min0, max0, 'Recommended threshold:', int( 0.9 * (max0 - min0))