Ejemplo n.º 1
0
    def generate_force(self, force):
        if force > 0.005:
            force = min(1, force)
            print "left", force
            dir = -1
            maxlevel = 0x7fff
            minlevel = 0x1000
            level = minlevel + int((maxlevel - minlevel) * force)
        elif force < -0.005:
            force = -force
            force = min(1, force)
            print "right", force
            dir = 1
            maxlevel = 0x7fff
            minlevel = 0x1000
            level = minlevel + int((maxlevel - minlevel) * force)
        else:
            print "center"
            dir = 0
            level = 0

        efx = sdl2.SDL_HapticEffect(type=sdl2.SDL_HAPTIC_CONSTANT, constant= \
            sdl2.SDL_HapticConstant(type=sdl2.SDL_HAPTIC_CONSTANT, direction= \
                                    sdl2.SDL_HapticDirection(type=sdl2.SDL_HAPTIC_CARTESIAN, dir=(dir,0,0)), \
            length=sdl2.SDL_HAPTIC_INFINITY, level=level, attack_length=0, fade_length=0))
        sdl2.SDL_HapticUpdateEffect(self.haptic, self.effect_id, efx)
Ejemplo n.º 2
0
    def __init__(self, stage):
        '''Constructor'''
        self.WARM_UP = 0
        self.QUALIFYING = 1
        self.RACE = 2
        self.UNKNOWN = 3
        self.stage = stage

        self.parser = msgParser.MsgParser()

        self.state = carState.CarState()

        self.control = carControl.CarControl()

        self.steer_lock = 0.785398
        self.max_speed = 100
        self.prev_rpm = None

        # Initialize the joysticks
        sdl2.SDL_Init(sdl2.SDL_INIT_JOYSTICK | sdl2.SDL_INIT_HAPTIC)
        assert sdl2.SDL_NumJoysticks() > 0
        assert sdl2.SDL_NumHaptics() > 0
        self.joystick = sdl2.SDL_JoystickOpen(0)
        self.haptic = sdl2.SDL_HapticOpen(0)
        assert sdl2.SDL_JoystickNumAxes(self.joystick) == 3
        assert sdl2.SDL_HapticQuery(self.haptic) & sdl2.SDL_HAPTIC_CONSTANT

        # Initialize force feedback
        efx = sdl2.SDL_HapticEffect(type=sdl2.SDL_HAPTIC_CONSTANT, constant= \
            sdl2.SDL_HapticConstant(type=sdl2.SDL_HAPTIC_CONSTANT, direction= \
                                    sdl2.SDL_HapticDirection(type=sdl2.SDL_HAPTIC_CARTESIAN, dir=(0,0,0)), \
            length=sdl2.SDL_HAPTIC_INFINITY, level=0, attack_length=0, fade_length=0))
        self.effect_id = sdl2.SDL_HapticNewEffect(self.haptic, efx)
        sdl2.SDL_HapticRunEffect(self.haptic, self.effect_id, 1)

        sdl2.SDL_HapticSetAutocenter(self.haptic, 0)
        sdl2.SDL_HapticSetGain(self.haptic, 100)

        self.stats = sensorstats.Stats(inevery=8)
Ejemplo n.º 3
0
is_wheel_connected = False
lights = False
gear = 0

if is_wheel_connected:

    isMoving = False
    sdl2.SDL_Init(sdl2.SDL_INIT_TIMER | sdl2.SDL_INIT_JOYSTICK
                  | sdl2.SDL_INIT_HAPTIC)
    joystick = sdl2.SDL_JoystickOpen(0)
    haptic = sdl2.SDL_HapticOpen(0)
    print("wheel - succesfully opened")
    efx = sdl2.SDL_HapticEffect(type=sdl2.SDL_HAPTIC_CONSTANT, constant= \
        sdl2.SDL_HapticConstant(type=sdl2.SDL_HAPTIC_CONSTANT, direction= \
            sdl2.SDL_HapticDirection(type=sdl2.SDL_HAPTIC_CARTESIAN, dir=(0, 0, 0)), \
                                length=sdl2.SDL_HAPTIC_INFINITY, level=0, attack_length=0, fade_length=0))
    effect_id = sdl2.SDL_HapticNewEffect(haptic, efx)
    sdl2.SDL_HapticRunEffect(haptic, effect_id, 1)
    sdl2.SDL_HapticSetAutocenter(haptic, 0)
    sdl2.SDL_HapticSetGain(haptic, 100)
    # Wykrywanie początkowego biegu:
    if sdl2.SDL_JoystickGetButton(joystick, 14) == 1:
        gear = -1
    elif sdl2.SDL_JoystickGetButton(joystick, 15) == 1:
        gear = 1
    else:
        gear = 0

# capture = cv2.VideoCapture('http://192.168.0.11:8080/video')
capture = cv2.VideoCapture('http://192.168.0.11:4747/video')
Ejemplo n.º 4
0
    def __init__(self):
        sdl2.SDL_Init(sdl2.SDL_INIT_TIMER | sdl2.SDL_INIT_JOYSTICK
                      | sdl2.SDL_INIT_HAPTIC)

        #print("Trying to find haptics")
        if (sdl2.SDL_NumHaptics() == 0):
            print("No haptic devices found (Driving kit not connected).")
            sdl2.SDL_Quit()

        for index in range(0, sdl2.SDL_NumHaptics()):
            print("Found", index, ":", sdl2.SDL_HapticName(index))
        index = 0

        self.haptic = sdl2.SDL_HapticOpen(index)
        if self.haptic == None:
            print("Unable to open device")
            sdl2.SDL_Quit()
            exit(0)
        else:
            #print("Using device", index)
            pass

        self.nefx = 0
        self.efx = [0] * 12
        self.id = [0] * 12
        supported = sdl2.SDL_HapticQuery(self.haptic)

        if (supported & sdl2.SDL_HAPTIC_SINE):
            print("   effect", self.nefx, "Sine Wave")
            self.efx[self.nefx] = sdl2.SDL_HapticEffect(type=sdl2.SDL_HAPTIC_SINE, periodic= \
                sdl2.SDL_HapticPeriodic(type=sdl2.SDL_HAPTIC_SINE, direction=sdl2.SDL_HapticDirection(type=sdl2.SDL_HAPTIC_POLAR, dir=(9000,0,0)), \
                period=1000, magnitude=0x4000, length=5000, attack_length=1000, fade_length=1000))
            self.id[self.nefx] = sdl2.SDL_HapticNewEffect(
                self.haptic, self.efx[self.nefx])
            self.nefx += 1

        if (supported & sdl2.SDL_HAPTIC_TRIANGLE):
            print("   effect", self.nefx, "Triangle")
            self.efx[self.nefx] = sdl2.SDL_HapticEffect(type=sdl2.SDL_HAPTIC_TRIANGLE, periodic= \
                sdl2.SDL_HapticPeriodic(type=sdl2.SDL_HAPTIC_SINE, direction=sdl2.SDL_HapticDirection(type=sdl2.SDL_HAPTIC_CARTESIAN, dir=(1,0,0)), \
                period=1000, magnitude=0x4000, length=5000, attack_length=1000, fade_length=1000))
            self.id[self.nefx] = sdl2.SDL_HapticNewEffect(
                self.haptic, self.efx[self.nefx])
            self.nefx += 1

        if (supported & sdl2.SDL_HAPTIC_SAWTOOTHUP):
            print("   effect", self.nefx, "Sawtooth Up")
            self.efx[self.nefx] = sdl2.SDL_HapticEffect(type=sdl2.SDL_HAPTIC_SAWTOOTHUP, periodic= \
                sdl2.SDL_HapticPeriodic(type=sdl2.SDL_HAPTIC_SAWTOOTHUP, direction=sdl2.SDL_HapticDirection(type=sdl2.SDL_HAPTIC_POLAR, dir=(9000,0,0)), \
                period=500, magnitude=0x5000, length=5000, attack_length=1000, fade_length=1000))
            self.id[self.nefx] = sdl2.SDL_HapticNewEffect(
                self.haptic, self.efx[self.nefx])
            self.nefx += 1

        if (supported & sdl2.SDL_HAPTIC_SAWTOOTHDOWN):
            print("   effect", self.nefx, "Sawtooth Down")
            self.efx[self.nefx] = sdl2.SDL_HapticEffect(type=sdl2.SDL_HAPTIC_SAWTOOTHDOWN, periodic= \
                sdl2.SDL_HapticPeriodic(type=sdl2.SDL_HAPTIC_SAWTOOTHDOWN, direction=sdl2.SDL_HapticDirection(type=sdl2.SDL_HAPTIC_CARTESIAN, dir=(1,0,0)), \
                period=500, magnitude=0x5000, length=5000, attack_length=1000, fade_length=1000))
            self.id[self.nefx] = sdl2.SDL_HapticNewEffect(
                self.haptic, self.efx[self.nefx])
            self.nefx += 1

        if (supported & sdl2.SDL_HAPTIC_RAMP):
            print("   effect", self.nefx, "Ramp")
            self.efx[self.nefx] = sdl2.SDL_HapticEffect(type=sdl2.SDL_HAPTIC_RAMP, ramp= \
                sdl2.SDL_HapticRamp(type=sdl2.SDL_HAPTIC_RAMP, direction=sdl2.SDL_HapticDirection(type=sdl2.SDL_HAPTIC_POLAR, dir=(9000,0,0)), \
                start=0x5000, end=0x0000, length=5000, attack_length=1000, fade_length=1000))
            self.id[self.nefx] = sdl2.SDL_HapticNewEffect(
                self.haptic, self.efx[self.nefx])
            self.nefx += 1

        if (supported & sdl2.SDL_HAPTIC_CONSTANT):
            print("   effect", self.nefx, "Constant Force")
            self.efx[self.nefx] = sdl2.SDL_HapticEffect(type=sdl2.SDL_HAPTIC_CONSTANT, constant= \
                sdl2.SDL_HapticConstant(type=sdl2.SDL_HAPTIC_CONSTANT, direction=sdl2.SDL_HapticDirection(type=sdl2.SDL_HAPTIC_CARTESIAN, dir=(1,0,0)), \
                length=5000, level=0x4000, attack_length=1000, fade_length=1000))
            self.id[self.nefx] = sdl2.SDL_HapticNewEffect(
                self.haptic, self.efx[self.nefx])
            self.nefx += 1