Pages: [1]   Go Down
Author Topic: Help me please  (Read 738 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

Hi everyone

I am using a Arduino Duemilanove and a Ultrasonic ranger to hold the altitude of an Quad-copter. I can use transmitter's switch to switch between altitude hold mode and manual throttle control mode. Once I switch to altitude mode, the Arduino will send a pwm to throttle dut to the range to the ground.  It is working only when it connected to my computer.  If it is not connect to computer, the manual control mode is good. If I switch to altitude hold mode, the motor will be out of control. Is there any problem in the software?

Test video:
The test video just show you how it works. The arduino has been connected to the computer. So it works well.

here is my software:


#include <Servo.h>
Servo myservo;
const int echo = 12;
const int trig = 13;
const int sw = 3;
const int th = 4;

void setup()
{
  
  pinMode(echo,INPUT);
  pinMode(trig,OUTPUT);
  int sensorValue = digitalRead(echo);
  int swValue = digitalRead(sw);
  int thValue = digitalRead(th);
  myservo.attach(9);
}

void loop()
  {  
  long duration, hold ,power;
  hold = pulseIn(sw,HIGH);
  if (hold>1500)  
  {
  digitalWrite(trig,LOW);
  delayMicroseconds(2);
  digitalWrite(trig,HIGH);
  delayMicroseconds(12);
  digitalWrite(trig,LOW);
  duration = pulseIn(echo,HIGH);
  duration = map(duration, 0, 1000, 135, 45);
  myservo.write(duration);
  }
 else {
   power = pulseIn(th,HIGH);
   power = map (power, 1000, 2000, 135, 45);
   myservo.write(power);
   delay(15);  
 }
}


* IMG_0591.jpg (451.18 KB, 1296x968 - viewed 8 times.)
« Last Edit: March 31, 2011, 12:52:03 pm by zeran » Logged

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

Why do you do this:
Code:
int sensorValue = digitalRead(echo);
  int swValue = digitalRead(sw);
  int thValue = digitalRead(th);
?
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.

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

I think the ultrasonic sensor does not work, when I pull out the USB.
Logged

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

Maybe you don't have enough current to power it.
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.

Left Coast, CA (USA)
Online Online
Brattain Member
*****
Karma: 331
Posts: 16543
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Maybe you don't have enough current to power it.

I agree, software should not change because of being powered via external power Vs USB power. It would be helpful if we could see a drawing of at least the power wiring between all the system components.

Lefty

Logged

0
Offline Offline
Sr. Member
****
Karma: 5
Posts: 476
what?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello, Have you considered how wind will change the result, have you thought about using GPS instead, just a thought
Logged

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

Quote
have you thought about using GPS instead
Quote
to hold the altitude of an Quad-copter
It would have to be differential GPS, I think.
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.

London, England
Offline Offline
Newbie
*
Karma: 1
Posts: 46
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Hello, Have you considered how wind will change the result, have you thought about using GPS instead, just a thought

I don't think exact position matters, so long as it doesn't fly into the ground. As for flying into anything else, GPS would not likely help much there either.
Logged

Pages: [1]   Go Up
Jump to: