Pages: [1]   Go Down
Author Topic: Traxxas VXL-3 ESC Testing  (Read 2095 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 309
Posts: 26485
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
« Last Edit: May 13, 2011, 02:20:39 pm by AWOL » Logged

"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.

Pages: [1]   Go Up
Jump to: