Hi! When I was finally going to download the code to my robot, the brain showed “Memory Permission Error”. I have tried to fix it, but other methods (restarting brain, uploading other code, different computer, etc) haven’t worked, so I’m sure its the code (below). I think its a problem in the code, but I’m not sure what to do.
#include "vex.h"
using namespace vex;
// A global instance of competition
competition Competition;
// define your global instances of motors and other devices here
/*---------------------------------------------------------------------------*/
/* Pre-Autonomous Functions */
/* */
/* You may want to perform some actions before the competition starts. */
/* Do them in the following function. You must return from this function */
/* or the autonomous and usercontrol tasks will not be started. This */
/* function is only called once after the V5 has been powered on and */
/* not every time that the robot is disabled. */
/*---------------------------------------------------------------------------*/
void pre_auton(void) {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
// All activities that occur before the competition starts
// Example: clearing encoders, setting servo positions, ...
}
/////////////////////////////////////////////////////////////////////////
float Rerror;
float Lerror;
float error;
float Rderivative;
float Lderivative;
float prevRerror;
float prevLerror;
float totalRerror;
float totalLerror;
float kP = 0;
float kI = 0;
float kD = 0;
float Roltage;
float Loltage;
float dist;
void driveFwdPID(int dist)
{
dist = dist * 35.25894125;
Rfront.setPosition(0,degrees);
Lfront.setPosition(0,degrees);
while(1)
{
Rerror = dist - Rfront.position(degrees); //P
Lerror = dist - Lfront.position(degrees);
error = (Rerror + Lerror)/2;
Rderivative = Rerror - prevRerror; //D
Lderivative = Lerror - prevLerror;
totalRerror += Rerror; //I
totalLerror += Lerror;
Roltage = (kP * Rerror + kI * totalRerror + kD * Rderivative); //the thing
Loltage = (kP * Lerror + kI * totalLerror + kD * Lderivative);
if(Roltage > 12)
{
Roltage = 12;
}
if(Loltage > 12)
{
Loltage = 12;
}
Rback.spin(vex::directionType::fwd, Roltage, voltageUnits::volt); //moves forward
Rfront.spin(vex::directionType::fwd, Roltage, voltageUnits::volt);
Lback.spin(vex::directionType::fwd, Loltage, voltageUnits::volt);
Lfront.spin(vex::directionType::fwd, Loltage, voltageUnits::volt);
prevRerror = Rerror;
prevLerror = Lerror;
if(-0.05 < error < 0.05)
{
break;
}
vex::task::sleep(15);
}
}
/*---------------------------------------------------------------------------*/
/* */
/* 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) {
driveFwdPID(10);
}
/*---------------------------------------------------------------------------*/
/* */
/* 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. */
/*---------------------------------------------------------------------------*/
float DrivePowerR = Controller1.Axis2.position(percent) * 0.12;
float DrivePowerL = Controller1.Axis3.position(percent) * 0.12;
int L1 = Controller1.ButtonL1.pressing();
int L2 = Controller1.ButtonL2.pressing();
int R1 = Controller1.ButtonR1.pressing();
int R2 = Controller1.ButtonR2.pressing();
void usercontrol(void) {
// User control code here, inside the loop
Rback.setStopping(coast);
Rfront.setStopping(coast);
Lback.setStopping(coast);
Lfront.setStopping(coast);
Rintake.setStopping(coast);
Lintake.setStopping(coast);
troller.setStopping(coast);
broller.setStopping(coast);
while (1) {
Rback.spin(fwd, DrivePowerR, volt);
Rfront.spin(fwd, DrivePowerR, volt);
Lback.spin(fwd, DrivePowerL, volt);
Lfront.spin(fwd, DrivePowerL, volt);
if(L1)
{
Rintake.spin(fwd, 12, volt);
Lintake.spin(fwd, 12, volt);
}
else if(L2)
{
Rintake.spin(reverse, 12, volt);
Lintake.spin(reverse, 12, volt);
}
else
{
Rintake.stop();
Lintake.stop();
}
if(R1)
{
troller.spin(forward, 12, volt);
broller.spin(forward, 12, volt);
}
else if(R2)
{
troller.spin(reverse, 12, volt);
broller.spin(reverse, 12, volt);
}
else
{
troller.stop();
broller.stop();
}
if(R1 && R2)
{
troller.spin(reverse, 12, volt);
broller.spin(forward, 12, volt);
}
else
{
troller.stop();
broller.stop();
}
// 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);
// Run the pre-autonomous function.
pre_auton();
// Prevent main from exiting with an infinite loop.
while (true) {
wait(100, msec);
}
}