Using an Ultrasonic sensor to constrain pitch/roll/throttle.

Using an Ultrasonic sensor to constrain pitch/roll/throttle.

Postby Spacenaut » Sun May 24, 2015 8:20 am

I want to add 5 ultrasonic sensors to my multiwii quad so that if the readings are less than a certain value, the corresponding pitch, roll or throttle value will be changed so the quad can't move in that direction. I'm using an arduino mega so connecting the ultrasonics is fine, its just I'm not sure how to program constrains onto the pitch,roll and throttle and where in multiwii.
Spacenaut
 
Posts: 6
Joined: Fri May 08, 2015 7:12 am

Re: Using an Ultrasonic sensor to constrain pitch/roll/throt

Postby pihlerm » Mon May 25, 2015 1:43 am

Hi Spacenaut,
I toyed with this idea a while ago. I'm not a multiwii dev but I think you'll ned a PID contoller for this.
Main PID's are handled in Multiwii.cpp around line 1500 (from my own understanding), so perhaps that's where the new PID should go as well.
The other place would be where GPS nav is handled.

I hope some of the devs reads this and perhaps gives us a better idea ;)

There is also the issue of how to make good input for the PID. I think it should work with rate of change of sonar distance as well as the distance (to ensure braking soon enough ;) There is of course the problem of the copter either reversing speed too much anf flying away from the 'wall', or perhaps an effecf of 'bouncing' off that wall if the input (RC or NAV or wind..) stays the same and sonar pid only 'guards' over a certain distance (anyway sonar is reliable only when very close <3-4 meters).

Just my thoughts. Perhaps i'm going in this direction after some other things first. Not sure about 5 sonars though (you need 1 pin for trigger and 1 pin for echo, so minimum 6 pins if triggering in unison - but then perhaps large capacitors will be needed for power).
pihlerm
 
Posts: 23
Joined: Tue Dec 09, 2014 6:40 pm

Re: Using an Ultrasonic sensor to constrain pitch/roll/throt

Postby FengShuiDrone » Tue May 26, 2015 3:31 am

.
Last edited by FengShuiDrone on Fri Aug 07, 2015 1:26 am, edited 1 time in total.
FengShuiDrone
 
Posts: 234
Joined: Wed Dec 24, 2014 1:20 am
Location: ......

Re: Using an Ultrasonic sensor to constrain pitch/roll/throt

Postby Spacenaut » Tue May 26, 2015 4:02 am

I don't think the amount of pins is the may concern, since I'm using a stock arduino mega. The biggest problem is that I'm not sure how to code it. My guess was that it would be something like this for each sensor:
Code: Select all
if ultrasonic1 < 30 {
    roll = roll.constrain(0,1500);
}

but I don't know if its possible to directly edit the RC values as a variable and if it is, where it would go.
Spacenaut
 
Posts: 6
Joined: Fri May 08, 2015 7:12 am

Re: Using an Ultrasonic sensor to constrain pitch/roll/throt

Postby pihlerm » Wed May 27, 2015 5:29 am

Hi,

the point in multiwii 2.4 is Multiwii.cpp around line 1500, where RD data is used as input to PID controllers.
There you could constrain that. But I don' think this will be ok..
Besides RC, there is all other data from gyros and accelerometers and NAV code .. that influences movement.
You could constrain the motor outputs..

I still think PID controller is the way to go.
pihlerm
 
Posts: 23
Joined: Tue Dec 09, 2014 6:40 pm

Re: Using an Ultrasonic sensor to constrain pitch/roll/throt

Postby danilo » Fri Jul 24, 2015 7:16 pm

5 sensors simultaneously working could cause the crash. Each sensor will be sampling (for distance) at the same time and this will cause delay on the total reaction time of your quad. For each sensor you must use an interrupt pin or else all code is stopped and will wait for pulsein(). You could try using additional Arduino for each sensor to get a fast reaction.

printed circuit board assembly china
danilo
 
Posts: 1
Joined: Fri Jul 24, 2015 3:58 pm


Return to Shields, boards and sensors

Who is online

Users browsing this forum: No registered users and 2 guests

cron