コード例 #1
0
class psControl():
    def __init__(self):
        os.putenv('DISPLAY', ':0.0')  # LINE SO WE DON'T HAVE TO CREATE WINDOW
        pygame.joystick.init()  # INITIALIZE JOYSTICK
        pygame.joystick.Joystick(0).init(
        )  # INITIALIZE JOYTSICK 0, CORRESPONDS TO THE CONTROL'S 2 JOYSTICKS
        self.trig = Trig()

    def joyStick(self, joystickAxis):
        pygame.init()  # INITIALIZE PYGAME
        for event in pygame.event.get():  # LISTENER TO LISTEN FOR EVENT.
            if event.type == pygame.JOYAXISMOTION:  # LISTEN FOR EVENT JOYSTICK AXIS MOTION
                pass  ## TRIED TO DO PRINT STATEMENTS HERE, WAY TOO FAST.

        joystick = pygame.joystick.Joystick(0).get_axis(
            joystickAxis
        )  # SET JOYSTICKAXIS AS JOYSTICK THAT THIS FUNCTION WILL RRETURN

        joystick = joystick * -1  # FOR SOME REASON UP IS NEGATIVE SO WE'LL FLIP THE SIGN CONVENTION
        if joystick == 0:  # THE COMMAND ABOVE WOULD YIELD A NEGATIVE ZERO, THIS WILL SET NEGATIVE EQUAL TO ZERO IF CURRENT AXIS VALUE IS ZERO
            joystick = 0

        if joystick < 0:  # IF THE USER PULLS BACK ON THE JOYSTICK
            joystick *= -1  # MAKE THE VALUE POSITIVE TO MAP TO PWM RANGE 0-255
            joystick = self.trig.map(
                joystick, 0, 1, 0, 255
            )  # MAP THAT NUMBER TO A RANGE FROM 0-255 WHICH CORRESPOND TO PWM FOR ARDUINO
            joystick *= -1  # MAKE THE VALUE NGEATIVE AGAIN
        else:
            joystick = self.trig.map(
                joystick, 0, 1, 0, 255
            )  # IF THE VALUE ISN'T ALREADY NEGATIVE JUST MAP IT TO THE PWM RANGE

        #print'Left Joystick Position: ', joystick # TEST LINE TO PRINT JOYSTICK VALUE
        return joystick  # RETURN JOYSTICK VALUE TO BE USED IN MAIN CODE

    def buttonPress(self, buttonNum):
        pygame.init()
        for event in pygame.event.get():  # LISTENER TO LISTEN FOR EVENT.
            if event.type == pygame.JOYAXISMOTION:  # LISTEN FOR EVENT
                pass  ## TRIED TO DO PRINT STATEMENTS HERE, WAY TOO FAST.

        buttonState = pygame.joystick.Joystick(0).get_button(
            buttonNum
        )  # CROSS is button 0, CIRCLE is button 1, TRIANGLE is button 2, SQUARE is button 3
        return buttonState  # BUTTONSTATE WILL RETURN 0 OR 1
コード例 #2
0
def psControl(leftJoystick, rightJoystick):

	pygame.joystick.init()
	pygame.joystick.Joystick(0).init()
	pygame.init()
	trig = Trig()

	os.putenv('DISPLAY', ':0.0')
	pygame.init()
	for event in pygame.event.get(): # User did something.
        	if event.type == pygame.JOYAXISMOTION:
			pass

	leftJoy = pygame.joystick.Joystick(0).get_axis(leftJoystick)
	rightJoy = pygame.joystick.Joystick(0).get_axis(rightJoystick)

	if leftJoy == 0:
		leftJoy = 0
	if rightJoy == 0:
		rightJoy = 0

	leftJoy = leftJoy * -1
	rightJoy = rightJoy * -1

	if leftJoy < 0:
		leftJoy *= -1
		leftJoy = trig.map(leftJoy, 0, 1, 0, 255)
		leftJoy *= -1
	else:
		leftJoy = trig.map(leftJoy, 0, 1, 0, 255)

	if rightJoy < 0:
		rightJoy *= -1
		rightJoy = trig.map(rightJoy, 0, 1, 0, 255)
		rightJoy *= -1
	else:
		rightJoy = trig.map(rightJoy, 0, 1, 0, 255)
	
	print'Left Joystick Position: ', leftJoy
	print'Right Joystick Position: ', rightJoy
	sleep(0.01)
コード例 #3
0
M2A = 12
M2B = 13

motorK = 2
maxPWM = 255

M1 = Motor("LEFT", M1En, M1A, M1B)
M2 = Motor("RIGHT", M2En, M2A, M2B)

M1.pinSet(a)
M2.pinSet(a)

# Initiate the classes needed for this file
nav = Navigation()
nav.position()  # line that calls the position of the beacon
trig = Trig()

# coordinates of each waypoint in the room, starting from door side clockwise.
xArr = [5.1, 8.0, 6.0, 2.4, 0]  # x-coordinates of the waypoints
yArr = [2.5, -1.5, -3.5, 0.3, 0]  # y-coorindates of the waypoints
x1 = 0
y1 = 0
x2 = 0
y2 = 0

# the buffer below is the leeway we allow the rover's position to account for
# i.e the position is never 100% accurate so we want a range of values that way once the rover hits those values
# it will perform some action based off these positions
buffer = 0.4
angleBuffer = 45
error = 0
コード例 #4
0
from Trig import Trig

trig = Trig()

# Map 5 from values to 0 to 1024
num = trig.map(0.5, 0, 1, 0, 255)

print(num)
コード例 #5
0
 def __init__(self):
     os.putenv('DISPLAY', ':0.0')  # LINE SO WE DON'T HAVE TO CREATE WINDOW
     pygame.joystick.init()  # INITIALIZE JOYSTICK
     pygame.joystick.Joystick(0).init(
     )  # INITIALIZE JOYTSICK 0, CORRESPONDS TO THE CONTROL'S 2 JOYSTICKS
     self.trig = Trig()