I am trying to use okapi but when I run my code on the brain there is a pop up that says, “memory permission error 00000000”. The error occurs when I try to use tank drive in okapi. This error does not occur when I comment out the line -
drive.tank(controller1.get_analog(pros::E_CONTROLLER_ANALOG_LEFT_Y),
controller1.get_analog(pros::E_CONTROLLER_ANALOG_RIGHT_Y));
What causes this error and how can I fix it.
edit: it also occurs anytime I try to control the drive using okapi, except when doing autonomous.
That’s strange. Memory permission error (aka segfault) can be caused by a few things.
Division by 0
Accessing an array element out of bounds
Using an invalid pointer
Passing a wrong type to a function
Any other run-time error the compiler does not catch
I might have an idea what is causing your error. If you look at the okapi documentation for tankhttps://pros.cs.purdue.edu/v5/okapi/api/chassis/controller/abstract-chassis-controller.html#id22
You can see that it accepts values in the range [-1, 1]. Likewise, if you look at the documentation for the okapi Controller getAnaloghttps://pros.cs.purdue.edu/v5/okapi/api/device/controller.html#getanalog you can see it also outputs in the range of [-1, 1]. The reason okapi chose to use that range is because it represents a percentage instead of an arbitrary number.
However, in your code above, you are not using an okapi Controller, you are using a pros Controller. Looking at that documentation Miscellaneous C++ API — PROS for V5 3.8.0 documentation, you can see it outputs values from the range of [-127, 127], which is not compatible with okapi. The solution might be to switch to using an okapi Controller like this:
I am not convinced that is what is causing the segfault, but give it a try.
If that does not solve the issue, can you show us where you define and create your chassis and controller?