1

I'm looking for a way/algorithm to make a robot balloon fly to a certain altitude. The robot is controlled by a Raspberry Pi and has a propeller. Propeller speed can be set to several values (it uses PWM so technically 1024 different power outputs). The balloon has a distance sensor pointing down, so it's possible to get the current height several times per second. Only idea I had so far was to measure the height constantly and set to max speed based on the height left to travel. This doesn't seem like the best option though, but can't figure out how to fit all power outputs in.

Any ideas would be welcome. I'm using Java to code the project but any high-level algorithm/description would be great!

Thx,

Magic

Magic Rune
  • 11
  • 2

2 Answers2

2

There is a great "game" available that lets you try and play around with exactly that problem: Colobot (seems to be open source now). Create a Winged-Grabber (or shooter if you are more the FPS type of person) and try to get it to fly to a specific destination using only the altitude and motor controls.

in general the Pseudo-Code by MadConan is the way to go, however the main task lies in writing a smart setPower function. In the end you need some smoothing function that reduces the power in relation to how close you are to your desired altitude, however the exact values of that function completely depend on your hardware and the weight of your final system.

Depending on how valuable and/or fragile your setup will be in the end, you might want to develop a learning system, that takes the under-/overshot as a basis to adjust the smoothing function while it runs. Make sure to take factors like up-/down-wind into your calculation.

TwoThe
  • 13,879
  • 6
  • 30
  • 54
  • Good explanation. My algorithm takes that into account (roughly). It will depend on how many measurements/sec are performed. As the balloon gets closer to the target value, the offset will get smaller and smaller and therefore the power should decrease as well. I agree, though, that it isn't quite that simple as it may not actually ever achieve the height. Again, depends on the sampling frequency. – MadConan Oct 31 '13 at 13:06
  • The sampling isn't the problem as you can easily interpolate the current position based on velocity, acceleration and time. The sensor is only the correction to your assumption, especially for outside factors like wind. I strongly suggest to give that game a try. I at first thought that it should be super-easy to control a bot like that, but then the first (luckily digital) crashes taught me otherwise. ;) – TwoThe Oct 31 '13 at 13:24
  • I was thinking of it being true vertical at all times, but now that I think about it, the wind will cause pitching, putting the sensor at an angle to the ground, which would give huge deltas from the actual height. So a full x, y and z coordinate sensor would be needed to compensate. – MadConan Oct 31 '13 at 13:34
  • Thank you for your answers. I will toy around with the suggested program this weekend to get a feel for it. The balloon is mainly for indoor use, so I don't expect wind will be much of an issue. How many measurements/second do you think would be good to provide sufficient information? – Magic Rune Oct 31 '13 at 17:50
  • It depends on the acceleration abilities of the balloon. The faster it can accelerate, the more often you'll need to sample. Realistically, probably 1/10 sec or faster to start with. – MadConan Oct 31 '13 at 18:01
  • Btw: unless you feel like playing through the entire campaign, there is a "Programming lesson" available for "Winged movement" (actually thrusters). You can use that one for any kind of tests, the game won't stop you from doing whatever you want. – TwoThe Oct 31 '13 at 18:09
  • This is probably overdue for OP, but for future developers: the phrase you are looking for is a [PID controller](https://colobot.info/). And, indeed, Colobot is a nice game to play with such things without risk of destroying the hardware. – ArturFH Jun 11 '17 at 01:26
1

Pseudo code.

  while(true){
    val height = getHeight(); // from sensor

    // Get the difference between the current height and
    // the TARGET height.  Positive values mean too low
    // while negative values mean too high
    val offset = TARGET_VALUE - height;

    // Set the power to some direct ratio of the offset
    // When the baloon is at 0 height, the offset should 
    // be relatively high, so the power will be set 
    // high.  If the offset is negative, the power will be 
    // set negative from the current power.
    setPower(offset);// I'll leave it up to you to figure out the ratio
}
MadConan
  • 3,749
  • 1
  • 16
  • 27