Memory Permission error 03801470

Hello world! Beginner programmer here.
I’ve been trying to fix a problem that occurs when i try to run my code on my brain - Memory Permission error 03801470.
I tried looking it up on google, but there was a grand total of four results, none of which speak of the programming language I’m using (C++).
Does anyone know how I can fix this?

Here’s my program

/*----------------------------------------------------------------------------*/
/*                                                                            */
/*    Module:       main.cpp                                                  */
/*    Author:       C:\Users\Robotics                                         */
/*    Created:      Wed Oct 11 2023                                           */
/*    Description:  V5 project                                                */
/*                                                                            */
/*----------------------------------------------------------------------------*/

// ---- START VEXCODE CONFIGURED DEVICES ----
// Robot Configuration:
// [Name]               [Type]        [Port(s)]
// Controller1          controller                    
// Catapult             motor         16              
// Wings                motor_group   17, 18          
// Rollah               motor         19              
// Left                 motor_group   12, 13          
// Right                motor_group   14, 15          
// ---- END VEXCODE CONFIGURED DEVICES ----

#include "vex.h"

using namespace vex;
//other variables
double TurnVal = Controller1.Axis3.position(percent);
double TurnVolts = TurnVal * 0.12;
//settings
double kP = 0.0;
double kI = 0.0;
double kD = 0.0;
double TurnkP = 0.0;
double TurnkI = 0.0;
double TurnkD = 0.0;

//autonomous settings
int desiredPosition = 200;
int desiredTurnValue = 0;

int Error;
// Error = sensor value - desired value : position -> speed -> accel
int prevError = 0;
// Position 20 miliseconds ago
int Derivative;
// Error - prevError : speed
int TotalError = 0;

int TurnError;
// Error = sensor value - desired value : position -> speed -> accel
int prevTurnError = 0;
// Position 20 miliseconds ago
int TurnDerivative;
// Error - prevError : speed
int TotalTurnError = 0;

bool ResetDrive = false;

bool enableDrivePID = true;
int drivePID(){

while (enableDrivePID){
  if (ResetDrive){
    ResetDrive = false;

  Left.setPosition(0,degrees);
  Right.setPosition(0,degrees);

  }

  //////////////
  //Lateral PID
   // position of the motors
  int leftMotorPosition = Left.position(degrees);
  int rightMotorPosition = Right.position(degrees);

  // average position of the motors
  int averageMotorPosition = (leftMotorPosition + rightMotorPosition)/2;

  // potential
  Error = averageMotorPosition - desiredPosition;

  // derivative
  Derivative = Error - prevError;

  // absement
  TotalError += Error;

  double LateralMotorPower = Error * kP + Derivative * kD + TotalError * kI;
  Left.spin(forward, LateralMotorPower + TurnVolts, voltageUnits::volt);
  Left.spin(forward, LateralMotorPower - TurnVolts, voltageUnits::volt);


  ////////////// 

 
  //////////////
  //Turn PID

  // average position of the motors
  int turnDifference = leftMotorPosition - rightMotorPosition;

  // potential
  TurnError = turnDifference - desiredTurnValue;

  // derivative
  TurnDerivative = TurnError - prevTurnError;

  // Integral
  //TotalError += TurnError;

  double turnMotorPower = TurnError * TurnkP + TurnDerivative * TurnkD + TotalError * kI;

  ////////////// 
  
  // program (duh)
  prevError = Error;
  vex::task::sleep(20);
}

  return 1;
}
 void autonomous(void) {
vex::task proot(drivePID);
ResetDrive = true;

  }
int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();
  //Auto win points

 
  //Manual control
  while (1) {
    //Driving
  Left.spin(forward, Controller1.Axis3.value(), percent);
  Right.spin(forward, Controller1.Axis2.value(), percent);
  wait(20, msec);
  if(Controller1.ButtonR1.pressing()){
   Catapult.spinFor(forward, 300,degrees);
   Catapult.spinFor(reverse, 300,degrees);
    }
    if(Controller1.ButtonL1.pressing()){
   Wings.spinFor(forward, 300,degrees);
   }
   if(Controller1.ButtonL2.pressing()){
     Wings.spinFor(reverse,300,degrees);
   }
   if(Controller1.ButtonUp.pressing()){
     Rollah.spin(forward);
   }
   else if(Controller1.ButtonDown.pressing()){
     Rollah.spin(reverse);
   }
   if(Controller1.ButtonLeft.pressing()){
     Rollah.stop();
   }
    }
}

(PID portion from @ TVA1814DeltaIII (Connor 1814D) on YouTube)

Update: I switched to the competition template, deleted everything, and pasted my code into the competition template, and it changed to Memory Permission error 038013BC.

The number is a memory address, it will change.

There’s nothing obvious there, probably something in robot_config.cpp, did you use graphical setup ?

5 Likes

The good news is that the address after the error is meaningless, the bad news is we need to see the rest of your code.

1 Like

I have no clue what graphical setup is.

It’s what generated this output. I assumed you were using VEXcode.

// ---- START VEXCODE CONFIGURED DEVICES ----
// Robot Configuration:
// [Name]               [Type]        [Port(s)]
// Controller1          controller                    
// Catapult             motor         16              
// Wings                motor_group   17, 18          
// Rollah               motor         19              
// Left                 motor_group   12, 13          
// Right                motor_group   14, 15          
// ---- END VEXCODE CONFIGURED DEVICES ----

so show the code where motors etc. are defined.

3 Likes
// ---- START VEXCODE CONFIGURED DEVICES ----
// Robot Configuration:
// [Name]               [Type]        [Port(s)]
// Controller1          controller                    
// Left                 motor_group   12, 13          
// Right                motor_group   14, 15          
// Catapult             motor         16              
// Wings                motor         17              
// Roller               motor_group   18, 19          
// ---- END VEXCODE CONFIGURED DEVICES ----

That’s comments, the code is in robot config

1 Like

I suggest trying to create a minimum reproducible example to narrow down what is wrong. To do this make a copy of your code then start deleting things until the memory permission error disappears. By using this method, you can isolate which section of the code is causing the error and more effectively find a solution.

1 Like
// VEXcode devices

extern controller Controller1;

extern motor Catapult;

extern motor_group Wings;

extern motor Rollah;

extern motor_group Left;

extern motor_group Right;

these?

No.
They should all be like this.

vex::motor       Catapult(PORT16);

usually in Robot_config.cpp if you are using VEXcode.

3 Likes
controller Controller1 = controller(primary);
motor Catapult = motor(PORT16, ratio18_1, false);
motor WingsMotorA = motor(PORT17, ratio18_1, false);
motor WingsMotorB = motor(PORT18, ratio18_1, false);
motor_group Wings = motor_group(WingsMotorA, WingsMotorB);
motor Rollah = motor(PORT19, ratio18_1, false);
motor LeftMotorA = motor(PORT12, ratio18_1, false);
motor LeftMotorB = motor(PORT13, ratio18_1, false);
motor_group Left = motor_group(LeftMotorA, LeftMotorB);
motor RightMotorA = motor(PORT14, ratio18_1, false);
motor RightMotorB = motor(PORT15, ratio18_1, false);
motor_group Right = motor_group(RightMotorA, RightMotorB);

This is what appears in my robot.config-cpp

ok, I looked at your code again, should have seen this originally.

This line has issues.

//other variables
double TurnVal = Controller1.Axis3.position(percent);

firstly, you are using Controller1 before it has been constructed as it gets constructed in robot-config.cpp.

secondly, that’s a pointless line of code anyway, assigning the position of Axis3 to a variable once before any other code runs. Doing that does not mean you can substitute TurnVal for Controller1.Axis3.position(percent);

so move these two lines of code to where those values are needed.

double TurnVal = Controller1.Axis3.position(percent);
double TurnVolts = TurnVal * 0.12;
3 Likes

Yes! It works! Thank you!