def __init__(self): self.PORT_NUMBER = 5004 self.DATA_SIZE = 1024 self.DEFAULT_PULSES_PER_SECOND = 0 self.DEFAULT_HOLD_MODE = "on" self.DEFAULT_STOP_MODE = "brake" self.DEFAULT_REGULATION_MODE = True self.MOTOR_STARTING_POSITION = 0 self.system_on = False self.YAW_LEFT = "yaw_left " self.YAW_RIGHT = "yaw_right" self.socket = None self.motor_lock = threading.Lock() self.unpacker = struct.Struct('f f') self.right_track_motor = Motor(port=Motor.PORT.A) self.left_track_motor = Motor(port=Motor.PORT.B) #self.servo_arm_pitch_motor=Motor(port=Motor.PORT.C) #self.servo_arm_roll_motor=Motor(port=Motor.PORT.D) self.camera_fov = 640 self.camera_av = self.camera_fov / 2 self.face_x = 0 self.face_y = 0 self.kp = 0.15625 # Constant for the proportional controller self.ki = 0 # Constant for the integral controller self.kd = 0 # Constant for the differential controller self.offset = self.camera_av # Offtset used to calculate error self.tp = 0 # Turning power of motors when there is no error self.previous_dt = 0 self.integral = 0 self.previous_err = 0 self.derivative = 0 self.coordinates_time_recv = 0 self.timeout = 0.2 #seconds self.face_coordinates_lock = threading.Lock() self.system_on_lock = threading.Lock() self.update_coordinates_thread = threading.Thread( target=self.update_face_coordinates) self.update_coordinates_thread.start() print "Setting up connection.\n" self.initialise_connection() print "Initialising Motors..\n" self.initialise_motors() print "Awaiting new connection...\n" self.update_face_coordinates()
def __init__(self, *args, **kwargs): super(TestMotor, self).__init__(*args, **kwargs) self.d = Motor(port=Motor.PORT.A)
app.debug = True # Create a random secrey key so we can use sessions app.config['SECRET_KEY'] = os.urandom(12) from ev3.ev3dev import Tone alarm = Tone() #head = None#Motor(port=Motor.PORT.A) right_wheel = None left_wheel = None button = None ir_sensor = None color_sensor = None try: right_wheel = Motor(port=Motor.PORT.B) left_wheel = Motor(port=Motor.PORT.C) button = TouchSensor() #ir_sensor = InfraredSensor() color_sensor = ColorSensor() alarm.play(200) except Exception as e: alarm.play(200) alarm.play(200) raise e right_wheel.position = 0 left_wheel.position = 0 right_wheel.reset() left_wheel.reset()
def __init__(self): self.left = Motor(port=Motor.PORT.B) self.right = Motor(port=Motor.PORT.C) self.left.reset() self.right.reset() self.gyro = GyroSensor()
C 2 red D 2 blue The program is stopped by pressing the baecon button. """ from ev3.ev3dev import Motor, NoSuchMotorError from ev3.lego import InfraredSensor from ev3.event_loop import EventLoop ir = InfraredSensor() motors = [] for port in 'ABCD': try: motor = Motor(port=port) motor.regulation_mode = False except NoSuchMotorError: motor = None motors.append(motor) buttons = [ (ir.REMOTE.RED_UP, ir.REMOTE.RED_DOWN), (ir.REMOTE.BLUE_UP, ir.REMOTE.BLUE_DOWN), ] def ir_changed(event): for channel in range(2): state = event.evaluation[channel] if state == ir.REMOTE.BAECON_MODE_ON:
import socket import ev3.ev3dev import time from ev3.ev3dev import Motor rightTrackMotor=Motor(port=Motor.PORT.A) leftTrackMotor=Motor(port=Motor.PORT.B) servoArmPitchMotor=Motor(port=Motor.PORT.C) servoArmRollMotor=Motor(port=Motor.PORT.D) print "Motors initialised." def setUp(motor): motor.reset() motor.regulation_mode = True motor.pulses_per_second_sp = 30 setUp(rightTrackMotor) setUp(leftTrackMotor) setUp(servoArmPitchMotor) setUp(servoArmRollMotor) print "Motors set up." #def yaw(direction): #left/right #def roll(direction): #left/right #def pitch(direction):