Memory Permission error ! 038038C0

I’ve tried everything I know how to and even asked help from the guy that taught me how to code, but I’m still getting this error. It generates on the brain at the start of the program and then the rest of the code won’t run. My thought is maybe a faulty brain but I’m unsure. The code is NOT in expert mode so there’s nothing off there that I would be able to fix. What’s new is the thirdwheeel function and most of the odometry programming, the setnames task works perfectly fine and has for months, along with the configured function. I can figure out other errors and annoyances later, for now I really need help on what is behind the memory permission error. Below is the full code.

#include "vex.h"
#include "math.h"
#include "cmath"
using namespace vex;
competition Competition;
//The radius of the wheels used for tracking.
const float WRadius = 1.25;
//The distance between tracking wheels. Not currently accurate. Should be in feet as to keep standard.
const float WBase = 15.5;
//Where the robot wants to be - where it is so that it knows where to go.
double OdErrorX, OdErrorY;
//Keeps average of potentiometer travel
int Dist = ((TWC + TWE)/2);
//Tracks the difference in wheels to track the orientation. Think of a drawing compass
int Orient = ((TWC - TWE)/WBase);
//Keeps difference between orientation error and inertial sensor
int OrientError = std::abs((IT21.heading(degrees)) - (Orient));
//Kept for X and Y coordinate updates. Distance/Circumfrence
int DistTrav = Dist / (WRadius * 2 * M_PI);
//Starting position of the robot, X
const float XposS = 4*12;
//Stored X value for the third wheel
int XStore;
//Starting position of the robot, Y
const float YposS = 0;
//Where the robot is, accounting for where it started
double Xpos = XposS+(DistTrav * cos(Orient));
//Where the robot is, accounting for where it started
double Ypos = YposS+(DistTrav * sin(Orient));
//Used to accelerate and decellerate the robot in the TurnToHeading
double kP = 0.8;
//Tracks the status of calibration of the inertial sensor
int Calibrated = 0;
//Stops the motors if the inertial is not calibrated.
void CalibratedRB (int Calibrated){
  if(Calibrated == (0))
  FL19.stop();
  FR16.stop();
  BL7.stop();
  BR3.stop();
}
task ThirdWheel;
int THW(){
while(1){
if((XStore == Xpos)||(XStore == Xpos+1)||(XStore == Xpos+2)||(XStore == Xpos-1)||(XStore == Xpos-2)){
Xpos = TWG.position(degrees);
}
else{
return(1);
}
{
wait(1, sec);
XStore = Xpos;
}
}
}
//posD are meant to represent the desired X and Y, in inches
void Odom(int XposD, int YposD, int OdSpeed){
//Stops the motors and the void if the robot is close enough to desired outcome
if((fabs(OdErrorX) < .2) && (fabs(OdErrorY) < 2)){
    FR16.stop(brake);
    BR3.stop(brake);
    FL19.stop(brake);
    BL7.stop(brake);
    return;
}
//Stops all of auton if the Orient is too far off. No break to stop the void, so the rest of auton will be a motionless robot
if(OrientError > 5){
    FR16.stop(brake);
    BR3.stop(brake);
    FL19.stop(brake);
    BL7.stop(brake);
//If the degree would go negative, make it positive and then account for negative to positive translation
if(Orient < 0){
  Orient = 360 - abs(Orient);
}
//Will help the robot keep how far it is from it's desired outcome horizontal
OdErrorX = Xpos - XposD;
//Will help the robot keep how far it is from it's desired outcome vertical
OdErrorY = Ypos - YposD;
//Moves the robot based on speed input. X Axis first
  //If the X position needs to decrease from where it is now, go right
    if(XposD < Xpos){
      FR16.spin(reverse, OdSpeed, pct);
      BR3.spin(forward, OdSpeed, pct);
      FL19.spin(reverse, OdSpeed, pct);
      BL7.spin(forward, OdSpeed, pct);
    }
    //If the X position needs to increase from where it is now, go left
    if(XposD > Xpos){
      FR16.spin(forward, OdSpeed, pct);
      BR3.spin(reverse, OdSpeed, pct);
      FL19.spin(forward, OdSpeed, pct);
      BL7.spin(reverse, OdSpeed, pct);
    }
    //If the Y position needs to increase from where it is now, go forward
    if((YposD > Ypos)&& OdErrorX < .2){
      FR16.spin(forward, OdSpeed, pct);
      BR3.spin(forward, OdSpeed, pct);
      FL19.spin(forward, OdSpeed, pct);
      BL7.spin(forward, OdSpeed, pct);
    }
    //If the Y position needs to decrease from where it is now, go back
    if((YposD < Ypos)&& OdErrorX < .2){
      FR16.spin(reverse, OdSpeed, pct);
      BR3.spin(reverse, OdSpeed, pct);
      FL19.spin(reverse, OdSpeed, pct);
      BL7.spin(reverse, OdSpeed, pct);
  }
wait(10, msec);
}
}
void TurnToHeading(double degree, int pctSpeed){
  double error = 0;
  while(1){
    int Heading = IT21.rotation(deg);
    error = degree - Heading;
    if(fabs(error) <kP){
      break;
    }
    double Speed = error*kP;
    //speeds up
    if(Speed > +pctSpeed){
      Speed = +pctSpeed;
    }
    //slows down
    if(Speed < -pctSpeed){
      Speed = -pctSpeed;
    }
    FR16.spin(reverse, Speed, pct);
    BR3.spin(reverse, Speed, pct);
    BL7.spin(forward, Speed, pct);
    FL19.spin(forward, Speed, pct);
    wait(10, msec);
  }
    FR16.stop(brake);
    BR3.stop(brake);
    BL7.stop(brake);
    FL19.stop(brake);
}
bool A, B, X, Y, RT, LT, Up, Dwn, R1, R2, L1, L2, fly, boolU, boolD, INB;
task SetNames;
int SN(){
//Buttons
     //R&L 1&2
       R1 = Controller1.ButtonR1.pressing();
       R2 = Controller1.ButtonR2.pressing();
       L1 = Controller1.ButtonL1.pressing();
       L2 = Controller1.ButtonL2.pressing();
     //Up Dwn LT RT
       Up = Controller1.ButtonUp.pressing();
       Dwn = Controller1.ButtonDown.pressing();
       LT = Controller1.ButtonLeft.pressing();
       RT = Controller1.ButtonRight.pressing();
     //A B X Y
       A = Controller1.ButtonA.pressing();
       B = Controller1.ButtonB.pressing();
       X = Controller1.ButtonX.pressing();
       Y = Controller1.ButtonY.pressing();
       wait(20, msec);
       return 1;
       }
// define your global instances of motors and other devices here
void pre_auton(void) {  
  vexcodeInit();
  IT21.calibrate();
  while(IT21.isCalibrating()){
    wait(100, msec);
  }
  Controller1.Screen.print("Calibrated");
  Calibrated = 1;
}
void autonomous(void) {
task ThirdWheel(THW);
CalibratedRB(Calibrated);
waitUntil(Calibrated == 1);
Odom(3,0,90);
TurnToHeading(180,90);
RO18.spinFor(forward, 180, deg);
Odom(4,2,90);
TurnToHeading(315,90);
{
FR16.spin(forward, 50, pct);
BR3.spin(forward, 50, pct);
FL19.spin(forward, 50, pct);
BL7.spin(forward, 50, pct);
IN5.spin(forward, 100, pct);
waitUntil(Xpos = 8);
FR16.stop(brake);
BR3.stop(brake);
FL19.stop(brake);
BL7.stop(brake);
IN5.stop();
}
TurnToHeading(225, 90);
FLY6.spin(forward, 60, pct);
}
void usercontrol(void) {
  while (1) {
    int Ax1 = Controller1.Axis1.value();
    //int Ax2 = Controller1.Axis2.value();
    int Ax3 = Controller1.Axis3.value();
    int Ax4 = Controller1.Axis4.value();
  task SetNames(SN);
  task ThirdWheel(THW);
  //manual drive controls
  if(abs(Ax1) >= 5 || abs(Ax3) >= 5 || abs(Ax4) >= 5){
    FL19.spin(fwd, Ax3+Ax1+Ax4, pct);
    FR16.spin(fwd, Ax3-Ax1-Ax4, pct);
    BL7.spin(fwd, Ax3+Ax1-Ax4, pct);
    BR3.spin(fwd, Ax3-Ax1+Ax4, pct);
  }
  else if(abs(Ax1) < 5 && abs(Ax3) < 5 && abs(Ax1) < 5)
  {
    FL19.stop(brake);
    FR16.stop(brake);
    BL7.stop(brake);
    BR3.stop(brake);
  }
//Intake
  if(Up == true && Dwn == false){
    IN5.spin(forward, 100, pct);
  }
  else if(Dwn == true && Up == false){
    IN5.spin(reverse, 100, pct);
  }
  else if(Up == false && Dwn == false){
    IN5.stop(hold);
  }
 else if(Up == true && Dwn == true){
    IN5.stop(hold);
  } 
  //Flywheel Spin
    if(R2) {
        FLY6.spin(forward, 100, pct);
    }
    else if(R1){
        FLY6.stop();
        fly = false;
        wait(20, msec);
      }
{
  //Expansion
    if(L2){
    EX20.spin(forward, 100, pct);
    }
    else if(L1){
      EX20.spin(reverse);
      wait(.7,sec);
      EX20.stop();
    }
}
  //roller
  {
    if(LT){
      RO18.spin(forward, 50, pct);
      wait(20,msec);
      RO18.stop();
    }
    else if(RT){
      RO18.spin(reverse, 100, pct);
      wait(20,msec);
      RO18.stop();
    }
  }
  //pneumatics
  {
    if(Y){
    PA.set(true); //retracts
    }
    if(A){
    PA.set(false); //extends
    }
    if(X){
    PB.set(true); //retracts
    }
    if(B){
    PB.set(false); //extends
    }
  }
  }
  wait(10, msec);
  }
int main() {
  task ThirdWheel(THW);
  Competition.autonomous(autonomous);
  Competition.drivercontrol(usercontrol);
  pre_auton();
    wait(100, msec);
  }

It’s difficult to help with projects like this without actually being able to run the code, that means attaching the whole project, as it’s tedious to recreate all the graphical configuration. But my initial feeling is things like this are likely to cause a memory error

//Keeps difference between orientation error and inertial sensor
int OrientError = std::abs((IT21.heading(degrees)) - (Orient));

as IT21 is unlikely to have been instantiated at this point in the code.
Initialize OrientError in main.

5 Likes

Update: New memory permission error. 03803898 this time. Below is the entire code, I included the device configuration this time. Any help is much appreciated.

// ---- START VEXCODE CONFIGURED DEVICES ----
// Robot Configuration:
// [Name]               [Type]        [Port(s)]
// Controller1          controller                    
// FL19                 motor         19              
// FR16                 motor         16              
// BL7                  motor         7               
// BR3                  motor         3               
// IN5                  motor         5               
// FLY6                 motor         6               
// EX20                 motor         20              
// PA                   digital_out   A               
// PB                   digital_out   B               
// RO18                 motor         18              
// IT21                 inertial      21              
// TWC                  encoder       C, D            
// TWE                  encoder       E, F            
// TWG                  encoder       G, H            
// ---- END VEXCODE CONFIGURED DEVICES ----

#include "vex.h"
#include "math.h"
#include "cmath"
using namespace vex;
competition Competition;
//The radius of the wheels used for tracking.
const float WRadius = 1.25;
//The distance between tracking wheels. Not currently accurate. Should be in feet as to keep standard.
const float WBase = 15.5;
//Where the robot wants to be - where it is so that it knows where to go.
double OdErrorX, OdErrorY;
//Keeps average of potentiometer travel
int Dist = ((TWC + TWE)/2);
//Tracks the difference in wheels to track the orientation. Think of a drawing compass
int Orient = ((TWC - TWE)/WBase);
//Kept for X and Y coordinate updates. Distance/Circumfrence
int DistTrav = Dist / (WRadius * 2 * M_PI);
//Starting position of the robot, X
const float XposS = 4*12;
//Stored X value for the third wheel
int XStore;
//Starting position of the robot, Y
const float YposS = 0;
//Where the robot is, accounting for where it started
double Xpos = XposS+(DistTrav * cos(Orient));
//Where the robot is, accounting for where it started
double Ypos = YposS+(DistTrav * sin(Orient));
//Used to accelerate and decellerate the robot in the TurnToHeading
double kP = 0.8;
//Tracks the status of calibration of the inertial sensor
int Calibrated = 0;
//Stops the motors if the inertial is not calibrated.
void CalibratedRB (int Calibrated){
  if(Calibrated == (0))
  FL19.stop();
  FR16.stop();
  BL7.stop();
  BR3.stop();
}
//posD are meant to represent the desired X and Y, in inches
void Odom(int XposD, int YposD, int OdSpeed){
//Stops the motors and the void if the robot is close enough to desired outcome
if((fabs(OdErrorX) < .2) && (fabs(OdErrorY) < 2)){
    FR16.stop(brake);
    BR3.stop(brake);
    FL19.stop(brake);
    BL7.stop(brake);
    return;
}
//If the degree would go negative, make it positive and then account for negative to positive translation
if(Orient < 0){
  Orient = 360 - abs(Orient);
}
//Will help the robot keep how far it is from it's desired outcome horizontal
OdErrorX = Xpos - XposD;
//Will help the robot keep how far it is from it's desired outcome vertical
OdErrorY = Ypos - YposD;
//Moves the robot based on speed input. X Axis first
  //If the X position needs to decrease from where it is now, go right
    if(XposD < Xpos){
      FR16.spin(reverse, OdSpeed, pct);
      BR3.spin(forward, OdSpeed, pct);
      FL19.spin(reverse, OdSpeed, pct);
      BL7.spin(forward, OdSpeed, pct);
    }
    //If the X position needs to increase from where it is now, go left
    if(XposD > Xpos){
      FR16.spin(forward, OdSpeed, pct);
      BR3.spin(reverse, OdSpeed, pct);
      FL19.spin(forward, OdSpeed, pct);
      BL7.spin(reverse, OdSpeed, pct);
    }
    //If the Y position needs to increase from where it is now, go forward
    if((YposD > Ypos)&& OdErrorX < .2){
      FR16.spin(forward, OdSpeed, pct);
      BR3.spin(forward, OdSpeed, pct);
      FL19.spin(forward, OdSpeed, pct);
      BL7.spin(forward, OdSpeed, pct);
    }
    //If the Y position needs to decrease from where it is now, go back
    if((YposD < Ypos)&& OdErrorX < .2){
      FR16.spin(reverse, OdSpeed, pct);
      BR3.spin(reverse, OdSpeed, pct);
      FL19.spin(reverse, OdSpeed, pct);
      BL7.spin(reverse, OdSpeed, pct);
  }
wait(10, msec);
}
task ThirdWheel;
int THW(){
while(1){
if((XStore == Xpos)||(XStore == Xpos+1)||(XStore == Xpos+2)||(XStore == Xpos-1)||(XStore == Xpos-2)){
Xpos = TWG.position(degrees);
}
else{
return(1);
}
{
wait(1, sec);
XStore = Xpos;
}
}
}
void TurnToHeading(double degree, int pctSpeed){
  double error = 0;
  while(1){
    int Heading = IT21.rotation(deg);
    error = degree - Heading;
    if(fabs(error) <kP){
      break;
    }
    double Speed = error*kP;
    //speeds up
    if(Speed > +pctSpeed){
      Speed = +pctSpeed;
    }
    //slows down
    if(Speed < -pctSpeed){
      Speed = -pctSpeed;
    }
    FR16.spin(reverse, Speed, pct);
    BR3.spin(reverse, Speed, pct);
    BL7.spin(forward, Speed, pct);
    FL19.spin(forward, Speed, pct);
    wait(10, msec);
  }
    FR16.stop(brake);
    BR3.stop(brake);
    BL7.stop(brake);
    FL19.stop(brake);
}
bool A, B, X, Y, RT, LT, Up, Dwn, R1, R2, L1, L2, fly, boolU, boolD, INB;
task SetNames;
int SN(){
//Buttons
     //R&L 1&2
       R1 = Controller1.ButtonR1.pressing();
       R2 = Controller1.ButtonR2.pressing();
       L1 = Controller1.ButtonL1.pressing();
       L2 = Controller1.ButtonL2.pressing();
     //Up Dwn LT RT
       Up = Controller1.ButtonUp.pressing();
       Dwn = Controller1.ButtonDown.pressing();
       LT = Controller1.ButtonLeft.pressing();
       RT = Controller1.ButtonRight.pressing();
     //A B X Y
       A = Controller1.ButtonA.pressing();
       B = Controller1.ButtonB.pressing();
       X = Controller1.ButtonX.pressing();
       Y = Controller1.ButtonY.pressing();
       wait(20, msec);
       return 1;
       }
// define your global instances of motors and other devices here
void pre_auton(void) {  
  vexcodeInit();
  IT21.calibrate();
  while(IT21.isCalibrating()){
    wait(100, msec);
  }
  Controller1.Screen.print("Calibrated");
  Calibrated = 1;
  //Keeps difference between orientation error and inertial sensor
}
void autonomous(void) {
int OrientError = std::abs((IT21.heading(degrees)) - (Orient));
task ThirdWheel(THW);
CalibratedRB(Calibrated);
//Stops all of auton if the Orient is too far off. No break to stop the void, so the rest of auton will be a motionless robot
if(OrientError > 5){
    FR16.stop(brake);
    BR3.stop(brake);
    FL19.stop(brake);
    BL7.stop(brake);
}
else{
waitUntil(Calibrated == 1);
Odom(3,0,90);
TurnToHeading(180,90);
RO18.spinFor(forward, 180, deg);
Odom(4,2,90);
TurnToHeading(315,90);
{
FR16.spin(forward, 50, pct);
BR3.spin(forward, 50, pct);
FL19.spin(forward, 50, pct);
BL7.spin(forward, 50, pct);
IN5.spin(forward, 100, pct);
waitUntil(Xpos = 8);
FR16.stop(brake);
BR3.stop(brake);
FL19.stop(brake);
BL7.stop(brake);
IN5.stop();
}
TurnToHeading(225, 90);
FLY6.spin(forward, 60, pct);
}
}
void usercontrol(void) {
  while (1) {
    int Ax1 = Controller1.Axis1.value();
    //int Ax2 = Controller1.Axis2.value();
    int Ax3 = Controller1.Axis3.value();
    int Ax4 = Controller1.Axis4.value();
  task SetNames(SN);
  task ThirdWheel(THW);
  //manual drive controls
  if(abs(Ax1) >= 5 || abs(Ax3) >= 5 || abs(Ax4) >= 5){
    FL19.spin(fwd, Ax3+Ax1+Ax4, pct);
    FR16.spin(fwd, Ax3-Ax1-Ax4, pct);
    BL7.spin(fwd, Ax3+Ax1-Ax4, pct);
    BR3.spin(fwd, Ax3-Ax1+Ax4, pct);
  }
  else if(abs(Ax1) < 5 && abs(Ax3) < 5 && abs(Ax1) < 5)
  {
    FL19.stop(brake);
    FR16.stop(brake);
    BL7.stop(brake);
    BR3.stop(brake);
  }
//Intake
  if(Up == true && Dwn == false){
    IN5.spin(forward, 100, pct);
  }
  else if(Dwn == true && Up == false){
    IN5.spin(reverse, 100, pct);
  }
  else if(Up == false && Dwn == false){
    IN5.stop(hold);
  }
 else if(Up == true && Dwn == true){
    IN5.stop(hold);
  } 
  //Flywheel Spin
    if(R2) {
        FLY6.spin(forward, 100, pct);
    }
    else if(R1){
        FLY6.stop();
        fly = false;
        wait(20, msec);
      }
{
  //Expansion
    if(L2){
    EX20.spin(forward, 100, pct);
    }
    else if(L1){
      EX20.spin(reverse);
      wait(.7,sec);
      EX20.stop();
    }
}
  //roller
  {
    if(LT){
      RO18.spin(forward, 50, pct);
      wait(20,msec);
      RO18.stop();
    }
    else if(RT){
      RO18.spin(reverse, 100, pct);
      wait(20,msec);
      RO18.stop();
    }
  }
  //pneumatics
  {
    if(Y){
    PA.set(true); //retracts
    }
    if(A){
    PA.set(false); //extends
    }
    if(X){
    PB.set(true); //retracts
    }
    if(B){
    PB.set(false); //extends
    }
  }
  }
  wait(10, msec);
  }
int main() {
  task ThirdWheel(THW);
  Competition.autonomous(autonomous);
  Competition.drivercontrol(usercontrol);
  pre_auton();

    wait(100, msec);
  }

edit: code tags added by mods.

1 Like

probably this code.
You are using encoders before they exist, and that code also has no real use at that point, remember all this is doing is initializing a variable (not to mention you are not asking for the encoder values correctly)

unrelated to the memory errors, but you should also read through this as task management in that code may cause issues.

3 Likes