Go Down

Topic: Traxxas VXL-3 ESC Testing (Read 2190 times) previous topic - next topic

sbergman75

Hello everyone. I'm relatively new to programming. I was hoping to post some code here. Let me know what ya'll think. Feel free to change it for the better. My methods aren't exactly pretty and not necessarily right. It isn't commented the least bit either.

The purpose of this program is to test the ESC at different speeds. It will alternate between the braking methods I know about from screwing around with it. It's a major work in progress. If one of you all is great with code or think this might be worthy of something please feel free to run with it.



Quote

// Testing the traxxas VXL 3s ESC by Seth Bergman. This works on mine from my Traxxas Rustler VXL.
// Please use with caution. I started with the Servo sketch by  Michal Rinott.

#include <Servo.h>  ;  // create servo object to control a servo

Servo VXL3sMotor;

int brakeLevel = 0;
int currentSpeed = 0;
int j = 1;
int i = 0;
const int maxNum = 30;  //up to 90?
int delayTime = 100;


void setup()

  Serial.begin(9600);
  VXL3sMotor.attach(12);  // attaches the servo on pin 9 to the servo object
  motor(0);
  delay(150);


void loop() {
  
  Serial.println();
  Serial.println("Checking Forward");
  checkForward(); 
  Serial.println();
  Serial.println("Checking Reverse");
  checkReverse(); 



void motor(int val){
  Serial.println(val);
  val = val + 90;
  VXL3sMotor.write(val);
}

void brake(int level){

  switch(level){
  case 0:
    Serial.println("Hard Stop");
    motor(-2*currentSpeed);
    delay(abs(currentSpeed));
    delay(1000);
    motor(0);
    break;

  case 1:
    motor(-currentSpeed);
    Serial.println("Soft Stop");
    delay(abs(currentSpeed)* 20);
    delay(1000);
    motor(0);
    break;

  case 2:
    motor(0);
    Serial.println("Coast Stop");
    delay(abs(currentSpeed) * 70);
    delay(1000);
    motor(0);
    break;
  }
}
void checkForward(){
  int step = maxNum/6;
  int i = 0;
  while(step <= maxNum){
    for (int i = -step + step; i < step+1; i++){
      currentSpeed = i;
      delay(delayTime);
      motor(currentSpeed);
    }
    if (currentSpeed > .8 * maxNum) brake(2); //keeps from braking too hard
    else if (currentSpeed >.5 * maxNum) brake(1); //keeps from braking too hard
    else brake(brakeLevel);
      
    j++;
    step += 5;
    if (brakeLevel == 2) brakeLevel = 0;
    else brakeLevel ++;
    if (j == 6){
      j = 1; 
    } 
  }
}

void checkReverse(){
  brakeLevel = 0;
  int step = -maxNum/6;
  int i = 0;
  while(step >= -maxNum){
    for (int i = -step + step; i > step-1; i--){
      currentSpeed = i;
      delay(delayTime);
      motor(currentSpeed);
    }
    if (abs(currentSpeed) > .8 * maxNum) brake(2); //keeps from braking too hard
    else if (abs(currentSpeed) >.5 * maxNum) brake(1); //keeps from braking too hard
    else brake(brakeLevel);
    j++;
    step -= 5;
    if (brakeLevel == 2) brakeLevel = 0;
    else brakeLevel ++;
    if (j == 6){
      j = 1; 
    } 
  }
}



Let me know what you think.

sbergman75

Ignore the j's too. I tried using an array of some sort with the different test points. It might work but I'm not too sure how.

AWOL

#2
May 13, 2011, 09:18 pm Last Edit: May 13, 2011, 09:20 pm by AWOL Reason: 1
Quote
Ignore the j's too.

OK. Consider them ignored.
Quote
I tried using an array of some sort with the different test points. It might work but I'm not too sure how

What are you talking about?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Go Up