Controls done

I know it has been a while since I posted last. The mechanical construction is almost done as I said in the last post. There's a little glimpse of it in the attached video.

The video I'm uploading is an over view of what the controls will be like. I haven't shoved everything into a backpack just yet. A thing to note is that the deadband for the motor controller is not analogous to the 90 degree position of a servo. It actually lies within about the 92-94 degree marks. That is what I did to modify the code. While plugged into a computer it also gives a few serial outputs that I was using for debugging. It is below the video if you're interested.



The new code:


// Kick Assist Code
// "Status" Kuo

#include <Servo.h>
 /*
 Talon Speed controllers work work the same way servos do for position I guess.
 Analog write doesn't properly do the magnitudes properly as I've learned before.
 */
Servo talon;  //creates a talon object
const int buttonPin = 2;     // the number of the pushbutton pin

int potpin = 0;  // analog pin used to connect the potentiometer
int val;    // variable to read the value from the analog pin

void setup()
{
  Serial.begin(9600);
  talon.attach(9);  // attaches the talon on pin 9 to the servo object
    // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);  
}

void loop()
{
  // read the state of the pushbutton value:
  int buttonState = digitalRead(buttonPin);
  // check if the pushbutton is pressed.
  // if it is...
  if (buttonState == HIGH) {  
    val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023)
  Serial.print(val);
  val = map(val, 0, 1023, 44, 94);     // scale it to use it with the servo (value between 0 and 180)
  Serial.print(" ");
  Serial.print(val);
  Serial.print("\n");    talon.write(val);                  // sets the talon speed according to the scaled value
    //delay(15);                           // waits for the servo to get there (I don't think this is nessessary for a speed controller)
  }
  //if the button isn't pressed, the motor won't turn on
  else {
    val = 93;
    talon.write(val);                  // sets the servo position according to the scaled value
    Serial.println("button not on");
  }

Comments