Altitude hold mode

Post here to get support
Post Reply
erlingrj
Beginner
Posts: 23
Joined: Mon May 12, 2014 12:17 pm

Altitude hold mode

Post by erlingrj »

I use the VM 0.4 and write programs in Python.

I can't get the altitude_mode to work with coding. I am able to search and connect to the Crazyflie and send setpoints and making it takeoff, but I am unable to go into altitdehold_mode.
This is my code, why doesnt it work?

Code: Select all

        print "sending initial thrust of 50 000"
      
        cf.commander.send_setpoint(0,0,0,50000);
        time.sleep(0.5);
        
        print "putting in althold"
        cf.param.set_value("flightmode.althold","True")
        
        print "Stay in althold for 7s"
        
        it=0
        
        while it<700:
            cf.commander.send_setpoint(0,0,0,32767)
            cf.param.set_value("flightmode.althold","True")
            time.sleep(0.01)
            it+=1
        
        print "Close connection"
        cf.commander.send_setpoint(0,0,0,0)
        cf.close_link();
The whole while loop is my interpretation of what is discussed in this thread: http://forum.bitcraze.se/viewtopic.php?f=6&t=883
When using a PS3-controller I can use the hovermode, but you have to hold the button, therefore it would make sense to set the altholdmode to "True" every 10ms a sort of "digital hold". I guess the error lies in the loop but Im really lost and could use some help.

Thank you
arnaud
Bitcraze
Posts: 2538
Joined: Tue Feb 06, 2007 12:36 pm

Re: Altitude hold mode

Post by arnaud »

I copy pasted your code is the ramp example in the _ramp_motors(self): method and it works even though it does not work. I mean: for 7sec the altitude hold is activated and you can see it by shaking the copter up and down but It seems that somehow the altitude reading is not accurate just after thrusting up and the altitude control just switch off the motors. After a while I got better result without the initial thrust up but by starting the copter in my hand in mid-air, so it seems that the thrust up had a bad influence and that it works better after a couple of try than at startup.

Also, try to cover the altitude sensor with some foam (I am cutting a bit from the box), it usually helps stabilizing the reading.

This is a lot of fun to test but I had to limit the altitude hold part to 3sec to limit a bit the banging around :).
Post Reply