Esempio n. 1
0
 def set_speeds(power_left, power_right,motor_multiplier=1.0):
     """
     As we have an motor hat, we can use the motors
     :param power_left: 
         Power to send to left motor
     :param power_right: 
         Power to send to right motor, will be inverted to reflect chassis layout
     """
     
     # If one wants to see the 'raw' 0-100 values coming in
     #print("source left: {}".format(power_left))
     #print("source right: {}".format(power_right))
     
     
     # Take the 0-100 inputs down to 0-1 and reverse them if necessary
     # this comment relates to the gpio zero robot and camjam board
     # we are using redboard motor controller and that wants demand +/-100
     power_left = (motor_multiplier * power_left) 
     power_right = (motor_multiplier * power_right) 
     
     # Print the converted values out for debug
     #print("left: {}".format(power_left))
     #print("right: {}".format(power_right))
     
     # If power is less than 0, we want to turn the motor backwards, otherwise turn it forwards
     # m1 is connected to left motor, +ve sends it forward
     redboard.M1(power_left)
     # m2 is connected to right motor, +ve sneds it backwards, hence we invert
     
     redboard.M2(-power_right)
def set_speeds(power_left, power_right):
    """
    As we have an motor hat, we can use the motors
    :param power_left:
    Power to send to left motor
    :param power_right:
    Power to send to right motor, will be inverted to reflect chassis layout
    """
    redboard.M1(-power_right)
    redboard.M2(power_left)
Esempio n. 3
0
 def stop_motors():
     """
     As we have an motor hat, stop the motors using their motors call
     """
     redboard.M1(0)
     redboard.M2(0)
Esempio n. 4
0
def main(stdscr):
    motor1 = 0
    motor2 = 0
    turbo = False
    rSteer = False

    keypress = 0
    up = 0
    stop = 0
    while True:

        curses.halfdelay(1)
        c = stdscr.getch()
        #print(c)  # Uncomment to show keypresses
        #print("\r")

        if c == ord('w'):
            keypress = 1
            print("Forward")
            print("\r")
            stop = 0
            motor1 = 100  # Set motor speed and direction
            motor2 = 100  # Set motor speed and direction

        elif c == ord('s'):
            keypress = 1
            stop = 0
            print("Backwards")
            print("\r")
            motor1 = -100
            motor2 = -100

        elif c == ord('a'):
            keypress = 1
            stop = 0
            print("Left")
            print("\r")
            motor1 = 100
            motor2 = -100

        elif c == ord('d'):
            keypress = 1
            stop = 0
            print("Right")
            print("\r")
            motor1 = -100
            motor2 = 100

        elif c == 32:  # Spacebar
            keypress = 1
            stop = 0
            print("Stop")
            print("\r")
            motor1 = 0
            motor2 = 0

        elif c == ord('r') and rSteer == False:
            keypress = 1
            stop = 0
            rSteer = True
            print("Reverse Steering")
            print("\r")

        elif c == ord('r') and rSteer == True:
            keypress = 1
            stop = 0
            rSteer = False
            print("Normal Steering")
            print("\r")

        elif c == ord('t') and turbo == False:
            keypress = 1
            stop = 0
            turbo = True
            print("Turbo on")
            print("\r")

        elif c == ord('t') and turbo == True:
            keypress = 1
            stop = 0
            turbo = False
            print("Turbo off")
            print("\r")

        # Pressing a key also produces a number of key up events.
        # This block of code only stops the robot moving after at least 4 key up events have been detected.
        # This makes driving the robot smoother but adds a short delay-
        # -from when you release the key until the robot stops.

        if c == -1:  # Check for key release
            stop += 1  # Count the number of key up events
        if keypress == 1 and stop > 5:  # Min = 4 - If the robot pauses when you hold a key down-
            # -increase this number.
            keypress = 0
            stop = 0
            print("Stop----------------------------------------")
            print("\r")
            motor1 = 0
            motor2 = 0

        # Half the speed if Turbo is off
        if turbo == True:
            m1 = motor1
            m2 = motor2

        elif turbo == False:
            m1 = motor1 / 2
            m2 = motor2 / 2

        # Reverse the steering if 'R' has been pressed
        if rSteer == False:
            redboard.M1(m1)
            redboard.M2(m2)

        else:
            redboard.M1(m2)
            redboard.M2(m1)
import Quaternion_shared_helper as Q
from simple_pid import PID
import atexit
import redboard

# Loop until the user clicks the close button.
done = False
running = False

pygame.init()

#kit = MotorKit()
#kit.motor1.throttle = 0.0
#kit.motor2.throttle = 0.0
redboard.M1(0.0)
redboard.M2(0.0)
leftThrottle = 0.0
rightThrottle = 0.0
currentLeftSpeed = 0.0
currentRightSpeed = 0.0
button_rotate = 0.0
grabWidth = 0.0  # 0.0 = fully open, 1.0 = fully closed
joy_forward = 0.0

quaternion = Q.Quaternion_shared_helper()

pidLeft = PID(0.32,
              0.8,
              0.02,
              setpoint=0,
              sample_time=0.01,
Esempio n. 6
0
def main(stdscr):
    keypress = 0
    up = 0
    stop = 0
    turbo = False
    motor1 = 0
    motor2 = 0
    rSteer = 0
    
    pan_centre = -19
    tilt_centre = 28

    pan_offset = 0
    tilt_offset = 0

    pan_limit = 25
    tilt_limit = 45

    pan(pan_centre)
    tilt(tilt_centre)

    while True:
        
        curses.halfdelay(1)
        c = stdscr.getch()
        #print(c)  # Uncomment to show keypresses
        #print("\r")
        
        if c == ord('w'):
            keypress = 1
            tilt_offset = tilt_offset if tilt_offset == -tilt_limit else tilt_offset - 1

        elif c == ord('s'):
            keypress = 1
            stop = 0
            tilt_offset = tilt_offset if tilt_offset == tilt_limit else tilt_offset + 1

        elif c == ord('a'):
            keypress = 1
            stop = 0
            pan_offset = pan_offset if pan_offset == -pan_limit else pan_offset - 1
			
        elif c == ord('d'):
            keypress = 1
            stop = 0
            pan_offset = pan_offset if pan_offset == pan_limit else pan_offset + 1

        if c == ord('i'):
            keypress = 1
            print("Forward")
            print("\r")
            stop = 0
            motor1 = -100  # Set motor speed and direction
            motor2 = -100  # Set motor speed and direction

        elif c == ord('k'):
            keypress = 1
            stop = 0
            print("Backwards")
            print("\r")
            motor1 = 100
            motor2 = 100

        elif c == ord('j'):
            keypress = 1
            stop = 0
            print("Left")
            print("\r")
            motor1 = -100
            motor2 = 100
			
        elif c == ord('l'):
            keypress = 1
            stop = 0
            print("Right")
            print("\r")
            motor1 = 100
            motor2 = -100

        elif c == 32:  # Spacebar
            keypress = 1
            stop = 0    
            motor1 = 0
            motor2 = 0            

        # Pressing a key also produces a number of key up events.
        # This block of code only stops the robot moving after at least 4 key up events have been detected.
        # This makes driving the robot smoother but adds a short delay- 
        # -from when you release the key until the robot stops.
  
        if c == -1:  # Check for key release
            stop += 1  # Count the number of key up events          
        if keypress == 1 and stop > 5:  # Min = 4 - If the robot pauses when you hold a key down- 
                                        # -increase this number.
            keypress = 0
            stop = 0
            motor1 = 0
            motor2 = 0
            
        pan(pan_centre - pan_offset)
        tilt(tilt_centre - tilt_offset)

        # Half the speed if Turbo is off
        if turbo == True:
            m1 = motor1
            m2 = motor2
        
        elif turbo == False:
            m1 = motor1 / 2
            m2 = motor2 / 2

        # Reverse the steering if 'R' has been pressed
        if rSteer == False:
            redboard.M1(m1)
            redboard.M2(m2)

        else:
            redboard.M1(m2)
            redboard.M2(m1)
def __init__(self):
    redboard.M1(0)
    redboard.M2(0)
def stop_moving():
    if not stop:
        stop = True
        redboard.M1(0)
        redboard.M2(0)
def move_right():
    while stop != True:
        redboard.M1(100)
        redboard.M2(100)
Esempio n. 10
0
def move_left():
    while stop != True:
        redboard.M1(-100)
        redboard.M2(-100)
Esempio n. 11
0
def move_backwards():
    """Move the rover in reverse at full speed"""
    while stop != True:
        redboard.M1(100)
        redboard.M2(-100)
Esempio n. 12
0
def move_forward():
    """Move the rover forwards at full speed"""
    while stop != True:  #don't forget to implement a stop!
        redboard.M1(-100)
        redboard.M2(100)
Esempio n. 13
0
import Motor

# Loop until the user clicks the close button.
done = False
running = False

pygame.init()

motorLeft = Motor.Motor(1)
motorRight = Motor.Motor(2)

#kit = MotorKit()
#kit.motor1.throttle = 0.0
#kit.motor2.throttle = 0.0
redboard.M1(0.0)
redboard.M2(0.0)
leftThrottle = 0.0
rightThrottle = 0.0
currentLeftSpeed = 0.0
currentRightSpeed = 0.0
button_rotate = 0.0
grabWidth = 0.0  # 0.0 = fully open, 1.0 = fully closed
joy_forward = 0.0
cameraAngle = 1280.0

quaternion = Q.Quaternion_shared_helper()

pidLeft = PID(0.4,
              0.8,
              0.02,
              setpoint=0,