I made the code for our bots driver control in VEXcode Pro V5 using the competition template, and whenever I upload my code onto my brain, it says “Memory Permission Error”. Apparently this issue is caused by either using something before initiating it, or having a “null pointer”. I looked through my code and couldn’t find any issues, and normally if it was having such an issue it should’ve failed to compile. Is this a hardware issue, because VEXcode Pro V5 is deprecated now, or is it my codes fault? If so, what part of my code is problematic?
/*----------------------------------------------------------------------------*/
/* */
/* Module: main.cpp */
/* Author: VEX */
/* Created: Thu Sep 26 2019 */
/* Description: Competition Template */
/* */
/*----------------------------------------------------------------------------*/
// ---- START VEXCODE CONFIGURED DEVICES ----
// ---- END VEXCODE CONFIGURED DEVICES ----
#include "vex.h"
using namespace vex;
// A global instance of competition
competition Competition;
// define your global instances of motors and other devices here
motor LeftMotorFront = motor(PORT18, ratio6_1, true);
motor LeftMotorMiddle = motor(PORT19, ratio6_1, true);
motor LeftMotorBack = motor(PORT20, ratio6_1, true);
motor RightMotorFront = motor(PORT17, ratio6_1, false);
motor RightMotorMiddle = motor(PORT15, ratio6_1, false);
motor RightMotorBack = motor(PORT16, ratio6_1, false);
motor topRoller = motor(PORT1, ratio18_1, false);
motor bottomRoller = motor(PORT2, ratio18_1, false);
motor topDecisiveMotor = motor(PORT3, ratio18_1, false);
motor_group LeftDrive(LeftMotorFront, LeftMotorBack, LeftMotorMiddle);
motor_group RightDrive(RightMotorFront, RightMotorBack, RightMotorMiddle);
digital_out DRSmech = digital_out(Brain.ThreeWirePort.A);
controller Controller1 = controller();
float SpeedLeft, SpeedRight, drsMech;
bool topOrMiddle = true;
void onevent_Controller1ButtonUp_pressed_0() {
if (fmod(drsMech,2.0) == 0.0) {
DRSmech.set(true);
drsMech += 1;
}
else {
DRSmech.set(false);
drsMech += 1;
}
}
void onevent_Controller1ButtonX_pressed_0() {
if (topOrMiddle == true) {
topOrMiddle = false;
}
else {
if (topOrMiddle == false) {
topOrMiddle = true;
}
}
}
void driveFor(double inches) {
double turns = inches / 12.57;
LeftDrive.spinFor(forward, turns, rev, 600, rpm, false);
RightDrive.spinFor(forward, turns, rev, 600, rpm, true);
}
void turnFor(double degrees, bool turnLeft) {
double turn_seconds = 0.00136 * degrees;
if (turnLeft) {
RightDrive.setTimeout(turn_seconds, seconds);
LeftDrive.setTimeout(turn_seconds, seconds);
RightDrive.spin(forward, 600, rpm);
LeftDrive.spin(reverse, 600, rpm);
}
else {
RightDrive.setTimeout(turn_seconds, seconds);
LeftDrive.setTimeout(turn_seconds, seconds);
RightDrive.spin(reverse, 600, rpm);
LeftDrive.spin(forward, 600, rpm);
}
}
void pre_auton(void) {
vexcodeInit();
// Initializing Robot Configuration. DO NOT REMOVE!
// All activities that occur before the competition starts
// Example: clearing encoders, setting servo positions, ...
}
/*---------------------------------------------------------------------------*/
/* */
/* Autonomous Task */
/* */
/* This task is used to control your robot during the autonomous phase of */
/* a VEX Competition. */
/* */
/* You must modify the code to add your own robot specific commands here. */
/*---------------------------------------------------------------------------*/
void autonomous(void) {
//driveArc(52.06, 72.9, 70.0, 0.763, true);
}
/*---------------------------------------------------------------------------*/
/* */
/* User Control Task */
/* */
/* This task is used to control your robot during the user control phase of */
/* a VEX Competition. */
/* */
/* You must modify the code to add your own robot specific commands here. */
/*---------------------------------------------------------------------------*/
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.
// ........................................................................
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);
// register event handlers
while (true) {
SpeedLeft = (Controller1.Axis1.position() + Controller1.Axis3.position()) / 8.3;
SpeedRight = (Controller1.Axis3.position() - Controller1.Axis1.position()) / 8.3;
LeftDrive.spin(forward, SpeedLeft, volt);
RightDrive.spin(forward, SpeedRight, volt);
if (Controller1.ButtonR1.pressing()) {
if (topOrMiddle == false) {
bottomRoller.spin(forward);
topRoller.spin(forward);
topDecisiveMotor.spin(forward);
}
else {
if (topOrMiddle == true) {
bottomRoller.spin(forward);
topRoller.spin(forward);
topDecisiveMotor.spin(reverse);
}
}
}
else {
if (Controller1.ButtonR2.pressing()) {
if (topOrMiddle == 0.0) {
bottomRoller.spin(reverse);
topRoller.spin(reverse);
topDecisiveMotor.spin(reverse);
}
else {
if (topOrMiddle == 1.0) {
bottomRoller.spin(reverse);
topRoller.spin(reverse);
topDecisiveMotor.spin(forward);
}
}
}
else {
bottomRoller.stop();
topDecisiveMotor.stop();
topRoller.stop();
}
}
}
// Run the pre-autonomous function.
pre_auton();
// Prevent main from exiting with an infinite loop.
while (true) {
wait(100, msec);
}
}