Show Posts
|
|
Pages: [1] 2 3
|
|
5
|
Using Arduino / Programming Questions / Re: servo control issue
|
on: January 27, 2013, 05:38:48 pm
|
|
Johnwasser, thats why i set the code at the end of the program within the while loop, it looks at the switchpin i.e. the position of the transmitter switch and if its changed it makes updwn 2 a different value to updwn. thus it exists the loop.
|
|
|
|
|
8
|
Using Arduino / Programming Questions / servo control issue
|
on: January 27, 2013, 05:22:52 pm
|
Can anyone help me with this code. The serial print at the end of the code does not print. Which makes me assume the program is sticking before the end. this would make sense as the motor and servo do not operate. #include <Servo.h> #define midlimit 1700 Servo myservoA;
int Abrake = 9;//brake signal for motor A int motorspdA = 3;//PWM speed signal for motor A int ch5; int motorA = 12; int sensorPinA = A0; // select the input pin for the current int switchpin = 22; int sensorValueA = 0; // variable to store the value coming from the sensor
void setup () {
pinMode (44, INPUT);//signal from the RC reciever channel 5 pinMode (12, OUTPUT);//motor A enable and direction HIGH or LOW pinMode (9, OUTPUT);//Brake motor A pinMode (4, OUTPUT);//servo A pin pinMode (switchpin, OUTPUT); myservoA.attach(4);
}
void loop () { Serial.begin(9600); int limitA = 300; //this is the current limit for motor A sensorValueA = analogRead(sensorPinA); //this reads the value of current for motorA and sets // the variable sensorValueA int iA = 0; //this creates and sets a variable named iA which we will use to make sure the //motors stop once they reach overcurrent condition myservoA.writeMicroseconds(900); ch5 = pulseIn(44, HIGH); Serial.println(ch5);
if (ch5 < midlimit) { digitalWrite(switchpin, HIGH); } else { digitalWrite(switchpin, LOW);
} int updwn = digitalRead(switchpin); //this sets the value of the variable updwn which is // read from transmitter switch int updwn2 = digitalRead(switchpin); //this sets the comparison value of updwn which is // read from transmitter switch Serial.println(updwn); delay(300); while (updwn == updwn2) { //the while loop here knows the current state of the switch // updwn. during the while loop it will continually check //the state of the switch by setting updwn2 therefore once the state of the switch //changes it will exit the while loop
if (updwn==1 && sensorValueA < limitA && iA==0) { analogWrite (motorspdA,255); digitalWrite (motorA,HIGH); digitalWrite (Abrake,LOW); } else if (updwn==0 && sensorValueA < limitA && iA==0) { analogWrite (motorspdA,255); digitalWrite (motorA,LOW); digitalWrite (Abrake,LOW); } else { analogWrite (motorspdA,0); digitalWrite (Abrake,LOW); myservoA.writeMicroseconds(2125); iA++; } } delay (200); sensorValueA = analogRead(sensorPinA); int ch5 = pulseIn(44, HIGH); if (ch5 < midlimit) { digitalWrite(switchpin, HIGH); } else { digitalWrite(switchpin, LOW); } updwn2 = digitalRead(switchpin); Serial.println(updwn2); }
|
|
|
|
|
12
|
Using Arduino / Programming Questions / more rc receiver issues
|
on: January 24, 2013, 03:42:11 pm
|
Hi Guys, below is the code written to operate 3 screw jack undercarriage motors, two operating from the arduino motor shield and the third from a third part device. The code has a flaw, the motors do not reverse on signal change. #include <Servo.h> Servo myservoA; Servo myservoB; //Servo myservoC;
// BOARD C CONNECTIONS
//IN1 control for motor, set LOW pin 0 //IN2 control for motor, set HIGH pin 1 //FB feedback to pin A2 //EN enable board set to high or low on pin 5 called motorCEN //INV is motor direction set to high or low on pin 10, called motorC //D2 is pwm motor control on pin 6 //free pins are..,1,0
int Bbrake=8;//brake signal for motor B int Abrake=9;//brake signal for motor A //int Cbrake=....;//brake signal for motor C.....not needed as no brake on board C
int motorspdB=11;//PWM speed signal for motor B int motorspdA=3;//PWM speed signal for motor A int motorspdC=6;//PWM speed signal for motor C
int motorA=12; int motorB=13; int motorC=10; int motorCEN=5;//motor c board enable int sensorPinA = A0; // select the input pin for the current int sensorPinB = A1; // select the input pin for the current int sensorPinC = A2; // select the input pin for the current
int sensorValueA = 0; // variable to store the value coming from the sensor int sensorValueB = 0; // variable to store the value coming from the sensor int sensorValueC = 0; // variable to store the value coming from the sensor int enable=2;//signal from the receiver //int limit=A0
void setup () { pinMode (13, OUTPUT);//motor B enable and direction HIGH or LOW pinMode (12, OUTPUT);//motor A enable and direction HIGH or LOW pinMode(10, OUTPUT);//motor C direction HIGH or LOW pinMode(5, OUTPUT);//motor C enable HIGH or LOW pinMode (8, OUTPUT);//Brake motor B pinMode (9, OUTPUT);//Brake motor A pinMode (2,INPUT);//receiver signal pin pinMode (4, OUTPUT);//servo A pin pinMode (7, OUTPUT);//servo B pin pinMode (0, OUTPUT); pinMode (1, OUTPUT); pinMode(motorspdC, OUTPUT); digitalWrite(motorCEN, HIGH); //pinMode(..., OUTPUT);servo C pin//no servo on motor C //pinMode (6, OUTPUT);//speed signal pin for motor C(not sure this is required) myservoA.attach(4); myservoB.attach(7); Serial.begin(9600); //myservoC.attach(...)need to decide on which pin; } void loop () { int limitA = 200; //this is the current limit for motor A int limitB = 200; //this is the current limit for motor B int limitC = 60; //this is the current limit for motor C //boolean switchstate = false; // boolean switchstate2 = false; int switchstate; int switchstate2; sensorValueB = analogRead(sensorPinB); //this reads the value of current for motorB and sets the variable sensorValueB sensorValueA = analogRead(sensorPinA); //this reads the value of current for motorA and sets the variable sensorValueA sensorValueC = analogRead(sensorPinC); //this reads the value of current for motorC and sets the variable sensorValueC //int updwn = pulseIn(enable, INPUT); //this sets the value of the variable updwn which is read from transmitter switch //int updwn2 = pulseIn(enable, INPUT); //this sets the comparison value of updwn which is read from transmitter switch int switchread = pulseIn(enable,INPUT); if (switchread > 14435) { switchstate = 1; } else { switchstate = 0; } //int updwncalc = sq(updwn - updwn2); //int updwncalc = (updwn-updwn2); //int updwncalc2 = (updwncalc*updwncalc); int iB = 0; //this creates and sets a variable named iB which we will use to make sure the motors stop once they reach overcurrent condition int iA = 0; //this creates and sets a variable named iA which we will use to make sure the motors stop once they reach overcurrent condition int iC = 0; //this creates and sets a variable named iC which we will use to make sure the motors stop once they reach overcurrent condition myservoA.writeMicroseconds(900); myservoB.writeMicroseconds(900); // myservoC.writeMicroseconds(900); switchstate2 = switchstate; delay(300); while (switchstate2 == switchstate) { //the while loop here knows the current state of the switch updwn. during the while loop it will continually check //the state of the switch by setting updwn2 therefore once the state of the switch changes it will exit the while loop if (switchstate = 1 && sensorValueB < limitB && iB==0) { analogWrite (motorspdB,255); digitalWrite (motorB,HIGH); digitalWrite (Bbrake,LOW); // Serial.print(switchstate); } else if (switchstate = 0 && sensorValueB < limitB && iB==0) { analogWrite (motorspdB,255); digitalWrite (motorB,LOW); digitalWrite (Bbrake,LOW); } else { analogWrite (motorspdB,0); digitalWrite (Bbrake,LOW); myservoB.writeMicroseconds(2095); iB++; } delay(300); if (switchstate = 1 && sensorValueA < limitA && iA==0) { analogWrite (motorspdA,255); digitalWrite (motorA,HIGH); digitalWrite (Abrake,LOW); } else if (switchstate = 0 && sensorValueA < limitA && iA==0) { analogWrite (motorspdA,255); digitalWrite (motorA,LOW); digitalWrite (Abrake,LOW); } else { analogWrite (motorspdA,0); digitalWrite (Abrake,LOW); myservoA.writeMicroseconds(2125); iA++; } delay(100); if (switchstate = 1 && sensorValueC < limitC && iC==0) { //digitalWrite(motorCEN, HIGH); // enable motor board **is this the correct way of creating a digital output signal, is this 5v?? //should this not be on throughout the loop? analogWrite (motorspdC,255); digitalWrite (motorC,HIGH);//determins direction of motor C //digitalWrite (Cbrake,LOW); Not required on motor C } else if (switchstate = 0 && sensorValueC < limitC && iC==0) { //digitalWrite(motorCEN, HIGH); // enable motor board digitalWrite (motorC,LOW); analogWrite (motorspdC,255); //digitalWrite (Cbrake,LOW);//no brake on c motor } else { analogWrite (motorspdC,0); //digitalWrite (Cbrake,LOW);//no brake on c motor //digitalWrite(motorCEN, LOW); // disable motor board //myservoC.writeMicroseconds(2095);//no servo on C motor iC++; } delay (200); sensorValueB = analogRead(sensorPinB); sensorValueA = analogRead(sensorPinA); sensorValueC = analogRead(sensorPinC); // updwn2 = pulseIn(enable, INPUT); // updwncalc = sq(updwn -updwn2); // Serial.print("switchstate2"); switchread = pulseIn(enable, INPUT); Serial.print(switchread); if (switchread < 14435) { //Serial.print(switchread); switchstate2 = 1; //Serial.print("switchstate2"); //switchstate2 = false; } else { switchstate2 = 0; //Serial.print(switchstate2); // switchstate2 = true; } } } Any help greatly appreciated
|
|
|
|
|