Set_rotation() works only once in Python, does't work again later

Using VEXcode 2.4.4-0 with EXP Brain v1.0.2 on Python.

The function set_rotation() works only once but subsequent calls to set_rotation() does not reseat the rotation reading.

# Begin project code
brain_inertial.calibrate()
wait(1, SECONDS)
while True:
    if brain.buttonRight.pressing():
        # reset the rotation to 0 degrees
        brain_inertial.set_rotation(0, DEGREES)
        wait(200, MSEC)

    print(brain_inertial.rotation(DEGREES))
    wait(30, MSEC)

The output:

0.0
0.0
0.0
0.0
-0.01
-0.01
0.0
0.0
0.01
0.09
0.09
0.34
0.34
0.45
0.45
0.55
0.55
0.62
0.62
0.7
0.7
0.87
0.87
1.02
1.02
1.22
1.22
1.33
1.33
1.48
1.71
1.71
1.96
1.96
2.27
2.27
2.64
2.64
3.1
3.1
3.66
3.66
4.36
4.36
5.48
5.48
6.53
6.53
7.8
7.8
8.64
8.64
9.73
9.73
11.11
11.11
11.88
11.88
11.97
11.89
11.89
11.89
11.81
11.81
12.93
15.7
15.7
16.57
16.57
16.57
17.25
17.25
19.16
20.27
20.27
21.63
21.63
22.7
22.7
22.93
22.93
23.0
23.0
23.08
23.08
23.21
23.21
23.25
23.25
23.34
23.34
23.35
23.35
23.35
23.35
23.37
23.37
23.35
23.35
23.36
23.36
23.39
23.39
23.37
23.36
23.36
23.36
23.36
23.36
23.36
23.35
23.35
23.36
23.36
-0.01	BUTTON PRESSED TO RESET, WORKING AS EXPECTED
0.01
0.01
0.0
0.0
-0.01
-0.01
0.01
0.01
0.02
0.02
0.01
0.01
0.0
0.0
0.02
0.02
-0.03
-0.03
0.0
0.0
0.02
0.02
0.0
0.0
0.03
0.03
0.08
0.08
0.12
0.12
0.22
0.22
0.37
0.37
0.48
0.67
0.67
0.75
0.75
0.94
0.94
1.09
1.09
1.25
1.25
1.48
1.48
1.91
1.91
2.0
2.0
2.32
2.32
2.46
2.46
2.71
2.88
2.88
3.05
3.05
3.4
3.4
3.58
3.58
3.73
3.73
3.91
3.91
4.14
4.14
4.4
4.4
4.58
4.58
4.76
4.76
4.91
4.91
5.16
5.16
5.44
5.44
5.67
5.67
5.96
5.96
6.15
6.38
6.38
6.51
6.51
6.81
6.81
6.81
7.08
7.08
7.38
7.63
7.63
8.01
8.01
8.51
8.51
9.11
9.11
9.79
9.79
10.27
10.27
10.44
10.44
10.68
10.68
10.95
10.95
11.38
11.38
11.64
11.64
11.84
11.84
12.09
12.09
12.34
12.34
12.61
12.9
12.9
13.19
13.19
13.19
13.58
13.58
13.68
13.68
13.67
13.69
13.69
13.67  	BUTTON PRESSED TO RESET, NOT WORKING AS EXPECTED
23.42
23.38
23.38
23.37
23.37
23.39
23.39
23.39
23.39
23.37
23.39

Basically, the set_rotation() does something like this:

0
1
2
3
0        <- reset the rotation with set_rotation(0, degrees), resets properly
1
2
3
4
23    <- reset the rotation with set_rotation(0, degrees) again but it's not taking

This is not an issue with C++:

int main() {
  BrainInertial.calibrate();
  wait(1, seconds);
  while (true) {
    if (Brain.buttonRight.pressing()) {
      BrainInertial.setRotation(0, degrees);
      wait(200, msec);
    }

    printf("%.2f\n", BrainInertial.rotation(degrees));
    wait(30, msec);
  }
}

For C++, the code is the same but set_rotation() works everytime. I was wondering if there was something wrong with my Python approach.

Thank you

I researched some things and found out that there is a check button on the brain that should set it to 0. If that is not there, you could try resetting the rotation with the reset_rotation command in python. The reset rotation should put it to 0.

This is a known bug, will be fixed in the next release of the Python VM.
see this.

4 Likes