1

So, basically, my problem is that my Ev3 Gyro Sensor clamps outputs beneath 0 to 0. If I were to rotate my robot clockwise, the gyro rotation would go up, but when I rotate my robot counter-clockwise, it would only go down until it reaches zero, then it stops.

Here is some code that could prove useful:
Setup of the gyro sensor:

    // Setting up the gyro sensor
    EV3GyroSensor gyro = new EV3GyroSensor(SensorPort.S2);
    gyro.switchMode("GYRO-ANG", 0);
    gyro.reset();



Getting the sample:

    public A[] getSample()
    {
        /** We first assert the mode here. **/
        assertMode();
        
        SampleProvider sampleProvider = baseSensor.getMode(baseSensor.getCurrentMode());
        
        float[] input = new float[sampleSize];
        sampleProvider.fetchSample(input, 0);
        
        @SuppressWarnings("unchecked")
        A[] castedArray = (A[]) Array.newInstance(clazz, sampleSize);
        
        // Please java. Tell me why I have to convert this to a Float first??!? This should all be done automatically...
        for(int i = 0; i < input.length; i++)
        {
            castedArray[i] = caster.apply(input[i]);
        }
        
        if(modifier.isPresent())
        {
            for(int i = 0; i < castedArray.length; i++)
            {
                /** Apply modifiers if necessary **/
                castedArray[i] = modifier.get().apply(castedArray[i]);
            }
        }
        
        return castedArray;
    }

    private void assertMode()
    {
        if(currentMode.isPresent())
        {
            if(System.currentTimeMillis() > (timeToSwitch + timeSinceSwitchCall))
            {
                baseSensor.switchMode(currentMode.get(), 0);
            }
        }
    }



Here is the log output:

Float value 21.0
Float value 20.0
20
Float value 19.0
Float value 18.0
18
Float value 16.0
Float value 16.0
16
Float value 15.0
Float value 15.0
15
Float value 14.0
Float value 14.0
14
Float value 13.0
Float value 13.0
13
Float value 12.0
Float value 11.0
11
Float value 11.0
Float value 11.0
11
Float value 11.0
Float value 11.0
11
Float value 10.0
Float value 10.0
10
Float value 9.0
Float value 7.0
7
Float value 6.0
Float value 6.0
6
Float value 0.0
Float value 0.0
0
Float value 0.0
Float value 0.0
0
Float value 0.0
Float value 0.0
0
Float value 0.0
Float value 0.0
0
Float value 0.0
Float value 0.0
0
Float value 0.0
Float value 0.0
0
Float value 0.0
Float value 0.0
0
Float value 0.0
Float value 0.0
0
Float value 0.0
Float value 0.0
0
Float value 0.0
Float value 0.0
0
Float value 0.0
Float value 0.0



I hope you can help me. Thanks.

2

I'm assuming you are using ev3dev-lang-java. It looks like this bug was fixed in v2.6.0. Source.

Make sure you are using the latest version. With your EV3 connected to the Internet, run sudo apt udpate && sudo apt upgrade.

1
  • Thanks for this answer. I apologize for being late to mark this as an answer... – Budschie Jan 30 at 18:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.