Memory permission error?

Occasionally my robot will not move upon starting a program and will give a screen saying “Memory permission error”. All of the motor ports blink red. The error never occurs while a program is running, it usually starts after ending a program and the controller will disconnect from the robot.

try going into the brain and go to settings; click delete all programs and then re download everything; that serves as a really good fix for a lot of related problems for my team.

1 Like

I’ve already done that and the error still occurs.

can you send your code? I don’t think its a coding issue but may as well check.

Are you using any 3-wire devices? If those get instantiated in a file other than the one where brain is declared, their instantiation will cause a memory permission error.

This error can also sometimes be caused by referencing a device that has not been properly instantiated yet. If you are using C++ (with multiple files), make sure to first declare all devices in a header file and make them global using the extern keyword.

1 Like

Here are the contents of my robot-config.cpp file:

#include “vex.h”

using namespace vex;

using signature = vision::signature;

using code = vision::code;

// A global instance of brain used for printing to the V5 Brain screen

brain Brain;

// VEXcode device constructors

motor Left1 = motor(PORT18, ratio6_1, true);

motor Left2 = motor(PORT19, ratio6_1, true);

motor Left3 = motor(PORT20, ratio6_1, true);

motor Right1 = motor(PORT8, ratio6_1, false);

motor Right2 = motor(PORT9, ratio6_1, false);

motor Right3 = motor(PORT10, ratio6_1, false);

motor Intake = motor(PORT3, ratio18_1, true);

motor PuncherMotorA = motor(PORT1, ratio18_1, true);

motor PuncherMotorB = motor(PORT17, ratio18_1, true);

motor_group Puncher = motor_group(PuncherMotorA, PuncherMotorB);

controller Controller1 = controller(primary);

digital_out Wings = digital_out(Brain.ThreeWirePort.G);

digital_out Hang = digital_out(Brain.ThreeWirePort.F);

digital_out RightBackWing = digital_out(Brain.ThreeWirePort.D);

rotation PuncherEncoder = rotation(PORT2, true);

inertial InertialSensor = inertial(PORT15);

rotation OdomSensor = rotation(PORT16, false);

digital_out LeftBackWing = digital_out(Brain.ThreeWirePort.E);

// VEXcode generated functions

// define variable for remote controller enable/disable

bool RemoteControlCodeEnabled = true;

/**

* Used to initialize code/tasks/devices added using tools in VEXcode Pro.
* This should be called at the start of your int main function.

*/

void vexcodeInit( void ) {

// nothing to initialize

}

And here is my main.cpp file:

#include “vex.h”

bool shift = false;

// bool shooting = false;

bool lowShooting = false;

bool reloading = false;
float encoderStartAngle;
float retractToAngle = 272; // 280

// ---- START VEXCODE CONFIGURED DEVICES ----
// Robot Configuration:
// [Name] [Type] [Port(s)]
// Left1 motor 18
// Left2 motor 19
// Left3 motor 20
// Right1 motor 8
// Right2 motor 9
// Right3 motor 10
// Intake motor 3
// Puncher motor_group 1, 17
// Controller1 controller
// Wings digital_out G
// Hang digital_out F
// LeftBackWing digital_out E
// RightBackWing digital_out D
// PuncherEncoder rotation 2
// InertialSensor inertial 15
// ---- END VEXCODE CONFIGURED DEVICES ----

using namespace vex;
competition Competition;

/*---------------------------------------------------------------------------*/
/* VEXcode Config <em>/
/</em> <em>/
/</em> Before you do anything else, start by configuring your motors and <em>/
/</em> sensors using the V5 port icon in the top right of the screen. Doing <em>/
/</em> so will update robot-config.cpp and robot-config.h automatically, so <em>/
/</em> you don’t have to. Ensure that your motors are reversed properly. For <em>/
/</em> the drive, spinning all motors forward should drive the robot forward. <em>/
/</em>---------------------------------------------------------------------------*/

/*---------------------------------------------------------------------------*/
/* JAR-Template Config <em>/
/</em> <em>/
/</em> Where all the magic happens. Follow the instructions below to input <em>/
/</em> all the physical constants and values for your robot. You should <em>/
/</em> already have configured your robot manually with the sidebar configurer. <em>/
/</em>---------------------------------------------------------------------------*/

Drive chassis(

//Specify your drive setup below. There are eight options:
//ZERO_TRACKER_NO_ODOM, ZERO_TRACKER_ODOM, TANK_ONE_ENCODER, TANK_ONE_ROTATION, TANK_TWO_ENCODER, TANK_TWO_ROTATION, HOLONOMIC_TWO_ENCODER, and HOLONOMIC_TWO_ROTATION
//For example, if you are not using odometry, put ZERO_TRACKER_NO_ODOM below:
TANK_TWO_ROTATION,

//Add the names of your Drive motors into the motor groups below, separated by commas, i.e. motor_group(Motor1,Motor2,Motor3).
//You will input whatever motor names you chose when you configured your robot using the sidebar configurer, they don’t have to be “Motor1” and “Motor2”.

//Left Motors:
motor_group(Left1, Left2, Left3),

//Right Motors:
motor_group(Right1, Right2, Right3),

//Specify the PORT NUMBER of your inertial sensor, in PORT format (i.e. “PORT1”, not simply “1”):
PORT15,

//Input your wheel diameter. (4" omnis are actually closer to 4.125"):
2.75,

//External ratio, must be in decimal, in the format of input teeth/output teeth.
//If your motor has an 84-tooth gear and your wheel has a 60-tooth gear, this value will be 1.4.
//If the motor drives the wheel directly, this value is 1:
0.75,

//Gyro scale, this is what your gyro reads when you spin the robot 360 degrees.
//For most cases 360 will do fine here, but this scale factor can be very helpful when precision is necessary.
360,

/*---------------------------------------------------------------------------*/
/* PAUSE! <em>/
/</em> <em>/
/</em> The rest of the drive constructor is for robots using POSITION TRACKING. <em>/
/</em> If you are not using position tracking, leave the rest of the values as <em>/
/</em> they are. <em>/
/</em>---------------------------------------------------------------------------*/

//If you are using ZERO_TRACKER_ODOM, you ONLY need to adjust the FORWARD TRACKER CENTER DISTANCE.

//FOR HOLONOMIC DRIVES ONLY: Input your drive motors by position. This is only necessary for holonomic drives, otherwise this section can be left alone.
//LF: //RF:
PORT1, -PORT2,

//LB: //RB:
PORT3, -PORT4,

//If you are using position tracking, this is the Forward Tracker port (the tracker which runs parallel to the direction of the chassis).
//If this is a rotation sensor, enter it in “PORT1” format, inputting the port below.
//If this is an encoder, enter the port as an integer. Triport A will be a “1”, Triport B will be a “2”, etc.
PORT11,

//Input the Forward Tracker diameter (reverse it to make the direction switch):
2.75,

//Input Forward Tracker center distance (a positive distance corresponds to a tracker on the right side of the robot, negative is left.)
//For a zero tracker tank drive with odom, put the positive distance from the center of the robot to the right side of the drive.
//This distance is in inches:
5.75,

//Input the Sideways Tracker Port, following the same steps as the Forward Tracker Port:
PORT16,

//Sideways tracker diameter (reverse to make the direction switch):
-2.75,

//Sideways tracker center distance (positive distance is behind the center of the robot, negative is in front):
5.75

);

int current_auton_selection = 0;
bool auto_started = false;

void pre_auton(void) {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
default_constants();

while(auto_started == false){ //Changing the names below will only change their names on the
Brain.Screen.clearScreen(); //brain screen for auton selection.
switch(current_auton_selection){ //Tap the brain screen to cycle through autons.
case 0:
Brain.Screen.printAt(50, 50, “Drive Test”);
break;
case 1:
Brain.Screen.printAt(50, 50, “Drive Test”);
break;
case 2:
Brain.Screen.printAt(50, 50, “Turn Test”);
break;
case 3:
Brain.Screen.printAt(50, 50, “Swing Test”);
break;
case 4:
Brain.Screen.printAt(50, 50, “Full Test”);
break;
case 5:
Brain.Screen.printAt(50, 50, “Odom Test”);
break;
case 6:
Brain.Screen.printAt(50, 50, “Tank Odom Test”);
break;
case 7:
Brain.Screen.printAt(50, 50, “Holonomic Odom Test”);
break;
}
if(Brain.Screen.pressing()){
//while(Brain.Screen.pressing()) {}
//current_auton_selection ++;
} else if (current_auton_selection == 8){
current_auton_selection = 0;
}
task::sleep(10);
}
}

void autonomous(void) {
auto_started = true;
switch(current_auton_selection){
case 0:
drive_test(); //This is the default auton, if you don’t select from the brain.
break; //Change these to be your own auton functions in order to use the auton selector.
case 1: //Tap the screen to cycle through autons.
drive_test();
break;
case 2:
turn_test();
break;
case 3:
swing_test();
break;
case 4:
full_test();
break;
case 5:
odom_test();
break;
case 6:
tank_odom_test();
break;
case 7:
holonomic_odom_test();
break;
}
}

void onevent_Controller1_ButtonR1_pressed_0(){

RightBackWing.set(!RightBackWing.value());
LeftBackWing.set(!LeftBackWing.value());

}

void onevent_Controller1_ButtonR2_pressed_0(){
Wings.set(!Wings.value());
}

// void onevent_Controller1_ButtonL2_pressed_0(){
// if(shift && !Wings.value()){
// if(!shooting){
// Puncher.spin(forward);
// Lift.set(true);
// MatchloadArm.set(true);
// }else{
// [//Puncher.stop](https://puncher.stop/)();
// Lift.set(false);
// MatchloadArm.set(false);
// reloading = true;
// }
// shooting = !shooting;
// }
// }

void onevent_Controller1_ButtonX_pressed_0(){
if(shift){
Puncher.stop();
}else{
if(!lowShooting){
Puncher.spin(forward);
[//MatchloadArm.set](https://matchloadarm.set/)(true);
}else{
[//Puncher.stop](https://puncher.stop/)();
reloading = true;
}
lowShooting = !lowShooting;
}

}

void onevent_Controller1_ButtonY_pressed_0(){
Hang.set(!Hang.value());
// if(shift && Lift.value()){
// [//LiftBoost.set](https://liftboost.set/)(!Lift.value());
// LiftBoost.set(true);
// }
}

/*---------------------------------------------------------------------------*/
/* <em>/
/</em> User Control Task <em>/
/</em> <em>/
/</em> This task is used to control your robot during the user control phase of <em>/
/</em> a VEX Competition. <em>/
/</em> <em>/
/</em> You must modify the code to add your own robot specific commands here. <em>/
/</em>---------------------------------------------------------------------------*/

void usercontrol(void) {
// User control code here, inside the loop
while (1) {
// This is the main execution loop for the user control program.
// Each time through the loop your program should update motor + servo
// values based on feedback from the joysticks.

```
// ........................................................................
// Insert user code here. This is where you use the joystick values to
// update your motors, etc.
// ........................................................................

if(Controller1.ButtonL1.pressing()){
  Intake.spin(forward); 
}
else if(Controller1.ButtonL2.pressing()){ //  && (!shift || Wings.value())
  Intake.spin(reverse); 
}
else{
  Intake.stop(); 
}


// if(Controller1.ButtonR2.pressing()){
//   shift = true; 
// }else{
//   shift = false; 
// }


if(reloading && PuncherEncoder.angle()-encoderStartAngle >= 360-retractToAngle){
  reloading = false; 
  Puncher.stop(); 
}

//Replace this line with chassis.control_tank(); for tank drive 
//or chassis.control_holonomic(); for holo drive.
chassis.control_arcade();

wait(20, msec); // Sleep the task for a short amount of time to
                // prevent wasted resources.


}
}

//
// Main will set up the competition functions and callbacks.
//
int main() {
// Set up callbacks for autonomous and driver control periods.
Competition.autonomous(autonomous);
Competition.drivercontrol(usercontrol);

// Initialize buttons.
Controller1.ButtonR1.pressed(onevent_Controller1_ButtonR1_pressed_0);
Controller1.ButtonR2.pressed(onevent_Controller1_ButtonR2_pressed_0);
[//Controller1.ButtonL2.pressed](https://controller1.buttonl2.pressed/)(onevent_Controller1_ButtonL2_pressed_0);
[//Controller1.ButtonX.pressed](https://controller1.buttonx.pressed/)(onevent_Controller1_ButtonX_pressed_0);
Controller1.ButtonX.pressed(onevent_Controller1_ButtonX_pressed_0);
Controller1.ButtonY.pressed(onevent_Controller1_ButtonY_pressed_0);

[//Puncher.setVelocity](https://puncher.setvelocity/)(20, percent);
Puncher.setVelocity(70, percent);
Intake.setVelocity(100, percent);

[//Puncher.setStopping](https://puncher.setstopping/)(hold);

PuncherEncoder.setPosition(0, degrees);
encoderStartAngle = PuncherEncoder.angle();

[//LiftBoost.set](https://liftboost.set/)(false);

// Run the pre-autonomous function.
pre_auton();

// Prevent main from exiting with an infinite loop.
while (true) {
wait(100, msec);
}
}

edit: code tags added by mods, please remember to use them.

Is there anything in the code that would cause this issue?

Im getting the same error also a Pl access error could you try including ur auton.cpp it might be a to high of a decimal

Also you dont need to configure ur imu sensor if your using Jar Template correct me if im wrong though @2775Josh

By “too high of a decimal” do you mean some of the movements are too precise? I’m not sure if that’s the case as we don’t use measurements past the tenths place (e.g., we would use 2.1 but not 2.15).

Ok, that’s not going to cause a memory permission error. These errors are always caused by incorrect use or pointers, whether using an instance of a global class that’s not yet created or just plain bad code.

4 Likes

Based on my code above, what do you think is the issue?

The code you posted won’t run without the “Drive” class, but my guess is probably something in that code.

1 Like

Here is a Github link to the full code for reference: GitHub - OverArchMC/VEX-Code

I would greatly appreciate it if you could take a look.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.