Temat podwozia wraca jak bumerang
Niestety durnych pomysłów ciąg dalszy
O ile ogarnąłem temat ehosondy i sterowania podwoziem to , jak to u mnie
, musiałem coś sobie dołożyć. Wymyśliłem sobie żeby do programu ehosondy dopisać prosty program sterujący ledami na bazie blinka i zrobiłem to tak:
Kod:
/*
Written by ediblefly 2015
Inspired by Benbojangles 2015
Written for Tarot TL65B44 copter landing gear
to set trigger altitude change "int trigger_altitude" to your desired alt itude in cm
The circuit:
*HC-SR04 Vcc connection attached to +5V Arduino
*HC-SR04 GND connection attached to gnd Arduino
*HC-SR04 Trig connection attached to pin 7
*HC-SR04 Echo connection attached to pin 8
*Sonar to APM connection is not active and will be developed in future versions of
the script
This example code is in the public domain.
*/
#include <Servo.h>
#include <Average.h>
#define CNT 10 //defines the size of the floating array used for averaging
//bigger the size: better averaging, very big arrays will cause long delays at the startup
Average<long> sonarRead(CNT);
Servo myservo; // create servo object to control a servo
const int pos1 = 15; // variable to store the servo position
const int pos2 =90; // not used
const int pos3 = 165; // variable to store the servo position
//data Pin number of the Arduino:
const int pingPin = 7; //trigger pin for HC-SR04 sonar unit
const int echoPin = 8; //echo pin for HC-SR04 sonar unit
const int sonarToAPM = 3; //reserved for future use
int ledPin = 13; //LED connected to digital pin 13 doubled by the onboard LED
int trigger_altitude = 195; //here we define the height in cm that we want to trigger
boolean IsGearDown = false;
int countLand = 0;
int countTakeOff = 0;
int attemptsL = 2; //change for acceptable number of falsepositives on landing
int attemptsTO = 4; //change for acceptable number of falsepositives on TakeOff
long CutOffDist = 1000; //cutoff dostance, this is usefull to cut off extreme values
//additional mechanism of averaging
void setup() {
// initialize serial communication:
Serial.begin(9600);
myservo.attach(9); // attaches the servo on pin 9 to the servo object
pinMode(ledPin, OUTPUT); // sets the digital pin as output
pinMode(echoPin, INPUT);
pinMode(pingPin, OUTPUT);
pinMode(sonarToAPM, OUTPUT);
}
void loop()
{
//distance in centimeters:
long duration, cm;
// The sensor is triggered by a HIGH pulse of 2 or more microseconds.
// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);
//fill the array for data averaging
int i;
//for(i=0; i<CNT; i++)
//{
// The same pin is used to read the signal from the sensor: a HIGH
// pulse whose duration is the time (in microseconds) from the sending
// of the ping to the reception of its echo off of an object.
duration = pulseIn(echoPin, HIGH);
// convert the time into a distance
cm = microsecondsToCentimeters(duration);
Serial.print(cm);
Serial.print("cm-real");
Serial.println();
if (cm < trigger_altitude)
{
sonarRead.push(1);
}
else
{
sonarRead.push(0);
}
delay(200);
//}
cm = sonarRead.mode();
//Serial.println(sonarRead.mode()); //mode(sonarRead, CNT);
Serial.print(CNT);
Serial.print("");
Serial.println();
Serial.print(cm);
Serial.print("");
Serial.println();
if (cm == 1)
{
digitalWrite(ledPin, HIGH); // sets the LED on
if (countLand < attemptsL)
{
countLand ++;
}
else if (IsGearDown == false)
{
myservo.write(pos1);
countLand = 0;
countTakeOff = 0;
IsGearDown = true; //Gear is Out - Landing
}
delay(15);
}
else if (cm == 0)
{
digitalWrite(ledPin, LOW);
if (countTakeOff < attemptsTO)
{
countTakeOff ++;
}
else if (IsGearDown == true)
{
myservo.write(pos3);
countTakeOff = 0;
countLand = 0;
delay(3000);
IsGearDown = false; //Gear is retracted - in the air
}
delay(15);
}
delay(15);
}
long microsecondsToInches(long microseconds)
{
// According to Parallax's datasheet for the sensor, there are
// 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
// second). This gives the distance travelled by the ping, outbound
// and return, so we divide by 2 to get the distance of the obstacle.
// See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf
return microseconds / 74 / 2;
}
long microsecondsToCentimeters(long microseconds)
{
// The speed of sound is 340 m/s or 29 microseconds per centimeter.
// The ping travels out and back, so to find the distance of the
// object we take half of the distance travelled.
return microseconds / 29 / 2;
*/
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin 6 as an output.
pinMode(6, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(6, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(6, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
Czyli kopiuj wklej i tylko nr pinu zmieniłem , takie kopiuj wklej chcę zrobić X4 ponieważ mam na 4 ramionach ledy, wiem zaraz powiecie, że są sterowniki do tego , ale to kolejna płytka , kolejne kable , a tu miałbym 2 w jednym i w jednym opakowaniu.
No i zgadnijcie ...... niedziałaaaaaa
Cokolwiek bym nie zrobił, wkleił na początku , na końcu, zmieniał nr pin i tak wywala mi błąd kompilacji
Mógł by mi ktoś pomóc bo korby dostanę i przez takie g... copter stoi nie skończony, a do póki wszystko w nim nie będzie tak jak zaplanowałem , nie poleci! prowizorek koniec!