I wrote this code which has no build, link, or compile errors, but has the error memory permission error 03802600 when running the code on the robot, not when downloading. Any suggestions?
this is all in V5 pro.
This is the code from the main.cpp file.
/*----------------------------------------------------------------------------*/
/* */
/* Module: main.cpp */
/* Author: C:\Users\17138 */
/* Created: Thu Nov 25 2021 */
/* Description: V5 project */
/* */
/*----------------------------------------------------------------------------*/
// ---- START VEXCODE CONFIGURED DEVICES ----
// Robot Configuration:
// [Name] [Type] [Port(s)]
// Controller1 controller
// Drivetrain drivetrain 1, 2, 3
// Claw motor 4
// Arm motor 5
// ---- END VEXCODE CONFIGURED DEVICES ----
#include "vex.h"
#include "Vis.h"
#include "robot-config.h"
using namespace vex;
competition Competition;
// function for ring grabbing
int leftmod = Controller1.Axis3.value()^3/100;
// set speed to a cubic for left
int rightmod = Controller1.Axis3.value()^3/100;
//set speed to cubic function right
// sets variables for gps use
double diistance;
double xa;
double ya;
double direct;
void grab(){
// grabs ring
Claw.spinFor(forward,250.0,degrees,true);
// raises arm
Arm.spinFor(reverse,400.0,degrees,true);
}
// gps movement
// balances robot
void balance(){
// balances (direction)
if(DrivetrainInertial.gyroRate(zaxis,dps)<0)
{
Drivetrain.drive(forward);
}
// balances (direction)
if(DrivetrainInertial.gyroRate(zaxis,dps)>0)
{
Drivetrain.drive(reverse);
}
}
// runs pre autonomous code
// runs code when program started
void pre_auton(void){
}
void autonomous(void){
// put autonomous code here
}
// function to call driver control
void usercontrol(void){
while(1){
// put driver code here
wait(20, msec);
}
}
int main() {
vexcodeInit();
// sets up callbacks for auton AND driver
Competition.autonomous(autonomous);
Competition.drivercontrol(usercontrol);
// runs pre auton= when started
// puts down arm
// moves to ring, using sensors?
//picks up ring
// moves to goal
// puts ring on goal, using sensor?
// choose sensors
// test sensors
while(true){
// calbrates inertial
DrivetrainInertial.calibrate();
// sets controls
motorL.spin(fwd,leftmod,percent);
motorR.spin(fwd,rightmod,percent);
wait(100,msec);
// takes picture of RING
Vis.takeSnapshot(RING);
// picks up ring if close enough
if(Vis.largestObject.exists && Vis.largestObject.width >5){
grab();
}
// balances robot with A pressing
if(Controller1.ButtonA.pressing()){
balance();
}// starts manual
if(Controller1.ButtonB.pressing()){
//spins claw fwd
if(Controller1.ButtonL2.pressing()){
Claw.spin(forward);
}
// spins ar fwd
if(Controller1.ButtonR2.pressing()){
Arm.spin(forward);
}
// spins claw reverse
if(Controller1.ButtonL1.pressing()){
Claw.spin(reverse);
}
// spins arm reverse
if(Controller1.ButtonR1.pressing()){
Arm.spin(reverse);
}
}
}
}
edit by mods to add code tags.
Don’t do this.
It’s meaningless, only access Controller1 inside a function.
I got rid of it and it still had the same problem.
Expanding on this, don’t calibrate inside the loop, as well.
You’ll want to read the value from the joystick each time thru the loop, as written, even if you didn’t get a memory error, the value of leftmod and rightmod would always be zero
I removed the segment completely, and still had the same problem. Should I post other the Header files?
about two years ago I had the problem that if I don’t assign initial values to variables, the memory permission error message would appear
try initializing all of them to zero
did this, did not solve the problem, but good suggestion.
In general, when the source of error is unclear, you may want to start with an empty competition template and add one construct at a time, verifying that everything still runs fine after each step.
Also, I don’t see you calling vexcodeInit() from pre_auton() function as it is shown in the linked kb.vex.com article.