Hello!
I’m decently new to using the Visual Studio Code extension for VEX-V5, and I’ve been encountering this error that says “Memory Permission Error! 03800320”. I’ve been scavenging through the forums to see if anyone had solutions, but none of them worked. I haven’t used any form of pointers so I doubt I would have a memory leak. Perhaps it’s because of how I structured my project? ( A custom “bg-logic.h” file for background logic, and the main.cpp file only running custom-made functions from the header. ) I’ve only narrowed it down to invoking the drive() function inside “main.cpp”.
main.cpp:
#include <bg-logic.h>
int main() {
vex::competition compet;
//> Defines an instance of the custom "vex_robot" class/category.
c_vex::vex_robot bob(
4.0, //> Wheel Diameter (inches)
0.5, //> PID Constant: Proportional
0.0, //> PID Constant: Integral
0.0 //> PID Constant: Derivative
);
//> Drives the robot forward 24 inches at a speed of 4 inches-per-second.
bob.drive(24, 4);
}
bg-logic.h:
#include <v5_vcs.h>
#include <math.h>
#include <v5.h>
#pragma once
namespace c_vex {
class vex_robot {
private:
float wheel_diam;
vex::motor l_motor = vex::motor(2, vex::gearSetting::ratio18_1, false);
vex::motor r_motor = vex::motor(3, vex::gearSetting::ratio18_1, false);
float kP;
float kI;
float kD;
////
public:
int compet_state = 1; //> 0 = Idle, 1 = Autonomous, 2 = Driver Control
vex_robot(int wheel_diam, float kP, float kI, float kD) {
this->wheel_diam = wheel_diam;
this->kP = kP;
this->kI = kI;
this->kD = kD;
}
bool drive(float distance_in_inches, float inches_per_second = 8) {
l_motor.stop(vex::brakeType::brake);
r_motor.stop(vex::brakeType::brake);
l_motor.resetPosition();
r_motor.resetPosition();
int elapsed_time_milli = 0;
int delta_time_milli = 20;
float target_rotation_in_deg = (distance_in_inches / (M_PI * wheel_diam)) * 360.0;
bool has_reached_target = false;
float l_error_term, r_error_term;
float l_prev_error, r_prev_error;
float l_derivative, r_derivative;
float l_total_error = 0, r_total_error = 0;
while (compet_state == 1 && !has_reached_target) {
l_error_term = target_rotation_in_deg - l_motor.position(vex::rotationUnits::deg);
r_error_term = target_rotation_in_deg - r_motor.position(vex::rotationUnits::deg);
l_prev_error = l_error_term;
r_prev_error = r_error_term;
l_derivative = (l_error_term - l_prev_error);
r_derivative = (r_error_term - r_prev_error);
l_total_error += l_error_term;
r_total_error += r_error_term;
double l_lat_motor_power_volts = (l_error_term * kP) + (l_total_error * kI) + (l_derivative * kD);
double r_lat_motor_power_volts = (r_error_term * kP) + (r_total_error * kI) + (r_derivative * kD);
l_motor.spin(vex::directionType::fwd, l_lat_motor_power_volts, vex::voltageUnits::volt);
r_motor.spin(vex::directionType::fwd, r_lat_motor_power_volts, vex::voltageUnits::volt);
if ((l_error_term >= target_rotation_in_deg && r_error_term >= target_rotation_in_deg)) {
has_reached_target = true;
}
vex::task::sleep(delta_time_milli);
elapsed_time_milli += delta_time_milli;
}
l_motor.stop(vex::brakeType::brake);
r_motor.stop(vex::brakeType::brake);
}
////
};
}
Keep in mind that I’m relatively new to C/C++ in the context of VEX-V5. Thanks!