def __init__(self, motorhat_addr=0x6f): # Setup the motorhat with the passed in address self._mh = Raspi_MotorHAT(addr=motorhat_addr) self.left_motor = self._mh.getMotor(1) self.right_motor = self._mh.getMotor(2) # Setup the Leds self.leds = leds_led_shim.Leds() # Set up servo motors for pan and tilt. self.servos = Servos(addr=motorhat_addr, deflect_90_in_ms=1) # Setup The Distance Sensors self.left_distance_sensor = DistanceSensor(echo=17, trigger=27, queue_len=2) self.right_distance_sensor = DistanceSensor(echo=5, trigger=6, queue_len=2) # Setup the Encoders EncoderCounter.set_constants(self.wheel_diameter_mm, self.ticks_per_revolution) self.left_encoder = EncoderCounter(4) self.right_encoder = EncoderCounter(26) # ensure the motors get stopped when the code exits atexit.register(self.stop_all)
def __init__(self, motorhat_addr=0x6f, drive_enabled=True): # Setup the motorhat with the passed in address self._mh = Raspi_MotorHAT(addr=motorhat_addr) # get local variable for each motor self.left_motor = self._mh.getMotor(1) self.right_motor = self._mh.getMotor(2) self.drive_enabled = drive_enabled # ensure the motors get stopped when the code exits atexit.register(self.stop_all) # Setup the line sensors self.left_line_sensor = LineSensor(23, queue_len=3, pull_up=True) self.right_line_sensor = LineSensor(16, queue_len=3, pull_up=True) # Setup The Distance Sensors self.left_distance_sensor = DistanceSensor(17, 27) self.right_distance_sensor = DistanceSensor(5, 6) # Setup the Encoders EncoderCounter.set_constants(self.wheel_diameter_mm, self.ticks_per_revolution) self.left_encoder = EncoderCounter(4) self.right_encoder = EncoderCounter(26) # Setup the Leds self.leds = leds_8_apa102c.Leds() # Set up servo motors for pan and tilt. self.servos = Servos(addr=motorhat_addr)
def __init__(self): self.display = None print("Booting SpotMicroAI") # self.display=RobotDisplay() self.gyro = Gyro() self.servos = Servos() self.Kinematic = Kinematic() self.network = Network() # For testing purposed self.mode = ModeStandby(self.servos)
def __init__(self, config_file): self.config = Config() self.config.read_config(config_file) self.servos = Servos(16, self.config.mimimum_pulse, self.config.maximum_pulse, self.config.kill_angle) legs = [] for i in range(4): leg = Leg(i, ) leg.servos(*(self.servos.servo[x] for x in leg_pins[i])) leg.offsets(*offsets[i]) leg.limbs(*lengths) legs.append(leg) self.leg0, self.leg1, self.leg2, self.leg3 = legs
def __init__(self, config_file): self.config = Config() self.config.read_config(config_file) self.servos = Servos(16, self.config.mimimum_pulse, self.config.maximum_pulse, self.config.kill_angle, self.config.angle_offsets) legs = [] for i in range(4): leg_config = self.config["leg"+str(i+1)] leg = Leg(leg_config["quadrants"], leg_config["positions"]) leg.servos(*(self.servos[x] for x in leg_config["servo_pins"])) leg.limbs(*leg_config["limb_lengths"]) legs.append(leg) self.leg0, self.leg1, self.leg2, self.leg3 = legs
def __init__(self): self.GPIO_FRONTTRIGGER = 20 self.GPIO_BACKTRIGGER = 5 self.GPIO_FRONTECHO = 6 self.GPIO_BACKECHO = 12 FRONTSERVO = 6 BACKSERVO = 7 #set GPIO direction (IN / OUT) GPIO.setmode(GPIO.BCM) GPIO.setup(self.GPIO_FRONTECHO, GPIO.IN) GPIO.setup(self.GPIO_BACKECHO, GPIO.IN) GPIO.setup(self.GPIO_FRONTTRIGGER, GPIO.OUT) GPIO.output(self.GPIO_FRONTTRIGGER, False) GPIO.setup(self.GPIO_BACKTRIGGER, GPIO.OUT) GPIO.output(self.GPIO_BACKTRIGGER, False) # initialise direction servos self.servos = Servos(FRONTSERVO, BACKSERVO) servoPositions = self.servos.FirstScanPosition() self.frontServoDirection = servoPositions[0] self.backServoDirection = servoPositions[1] self.scannerActive = False self.endthread = False self.HistoryFront = [[0.0, 0.0, 0.0, 0.0, 0.0]] self.HistoryBack = [[0.0, 0.0, 0.0, 0.0, 0.0]] self.FrontDeltas = [[0.0, 0.0, 0.0, 0.0, 0.0]] self.BackDeltas = [[0.0, 0.0, 0.0, 0.0, 0.0]] self.FrontDeltaDelta = [0.0, 0.0, 0.0, 0.0, 0.0] self.BackDeltaDelta = [0.0, 0.0, 0.0, 0.0, 0.0] # initialise current distance readings self.frontDistance = { ServoDirection.Left: -1.0, ServoDirection.OffLeft: -1.0, ServoDirection.Ahead: -1.0, ServoDirection.OffRight: -1.0, ServoDirection.Right: -1.0 } self.backDistance = { ServoDirection.Left: -1.0, ServoDirection.OffLeft: -1.0, ServoDirection.Ahead: -1.0, ServoDirection.OffRight: -1.0, ServoDirection.Right: -1.0 } time.sleep(1)
def __init__(self, motorhat_addr=0x6f): # set up motorhat with address parameter self._mh = Raspi_MotorHAT(addr=motorhat_addr) # get local variable for each motor self.left_motor_rear = self._mh.getMotor(1) self.left_motor_front = self._mh.getMotor(2) self.right_motor_rear = self._mh.getMotor(4) self.right_motor_front = self._mh.getMotor(3) # make sure motors stop when code exits atexit.register(self.stop_motors) # Set up servo motors for pan and tilt self.servos = Servos(addr=motorhat_addr)
def __init__(self, motorhat_addr=0x6f): self._mh = Raspi_MotorHAT(addr=motorhat_addr) self.left_motor = self._mh.getMotor(1) self.right_motor = self._mh.getMotor(2) atexit.register(self.stop_motors) # Setup the line sensors self.right_line_sensor = LineSensor(23, queue_len=3, pull_up=True) self.left_line_sensor = LineSensor(16, queue_len=3, pull_up=True) self.right_line_sensor_stuck = "" self.left_line_sensor_stuck = "" self.servos = Servos(addr=motorhat_addr)
def __init__(self, motorhat_addr=0x6f): # Setup the motorhat with the passed in address self._mh = Raspi_MotorHAT(addr=motorhat_addr) # get local variable for each motor self.left_motor = self._mh.getMotor(1) self.right_motor = self._mh.getMotor(2) # ensure the motors get stopped when the code exits atexit.register(self.stop_all) # Setup the line sensors self.left_line_sensor = LineSensor(23, queue_len=3, pull_up=True) self.right_line_sensor = LineSensor(16, queue_len=3, pull_up=True) # Setup the Leds self.leds = leds_8_apa102c.Leds() # Set up servo motors for pan and tilt. self.servos = Servos(addr=motorhat_addr)
def __init__(self, motorhat_addr=0x6f): # Setup the motorhat with the passed in address self._mh = Raspi_MotorHAT(addr=motorhat_addr) # get local variable for each motor self.left_motor = self._mh.getMotor(1) self.right_motor = self._mh.getMotor(2) # Setup The Distance Sensors self.left_distance_sensor = DistanceSensor(echo=17, trigger=27, queue_len=2) self.right_distance_sensor = DistanceSensor(echo=5, trigger=6, queue_len=2) # Setup the Leds self.leds = leds_led_shim.Leds() # Set up servo motors for pan and tilt. self.servos = Servos(addr=motorhat_addr) # ensure the motors get stopped when the code exits atexit.register(self.stop_all)
from servos import Servos servos = Servos(num=16, mimimum_pulse=450, maximum_pulse=2450, kill_angle=90) servo = servos[int(input("What servo: "))] x = input("What angle: ") while x != "end": try: servo.angle = float(x) except ValueError: print("Must input a number") x = input("New angle: ")
synced = False ### utils def _reset_servos(): s.setXAxis(SERVO_CENTER) s.setYAxis(SERVO_CENTER) ### code trigger = Trigger() # servo driver conf s = Servos(SERVO_I2C_ADDRESS, SERVO_XAXIS_CHANNEL, SERVO_YAXIS_CHANNEL, SERVO_PWM_FREQ) _reset_servos() def signal_handler(signal, frame): _reset_servos() trigger.reset() sys.exit(0) signal.signal(signal.SIGINT, signal_handler) # pi camera setup # camera = picamera.PiCamera() ## myo websocket handlers
def __init__(self): print("Initialising") self.servos=Servos() self.Kinematic=Kinematic()
from modes import AbstractMode from servos import Servos class ModeStandby(AbstractMode): def __init__(self,servos): AbstractMode.__init__(self,servos) def init(self): self.servos.angle(1,50) # [self.servos.angle(v,50) for v in range(0,1)] def update(self): pass if __name__ == "__main__": try: servos=Servos() ms = ModeStandby(servos) ms.init() except Exception as e: print(e) pass