Hovering scripts

Firmware/software/electronics
Post Reply
RyanMco
Expert
Posts: 159
Joined: Tue Apr 09, 2019 6:15 am

Hovering scripts

Post by RyanMco »

Hi !
How can I send from crazyflie_ros's scripts that this repository found in gitHub a command to my crazyflie in order to hover on specific height? like for example If I'm not using crazyflie_ros scripts, if I use crazyflie_python scripts then I was sending

Code: Select all

mc.up(0.5)
and with timesleep then my crazyflie was hovering on specific height.
but in my crazyflie_ros scripts specifically Im using test_high_level.py there's no command for letting my crazyflie to hover on specific height like mc.up, is there any commands that's already written in crazyflie_ros's python that I can use it for hovering my crazyflie to specific height? if not, then what you please suggest me to change in my firmware in order for instance by goto command to let my crazyflie hover on specific height? lets assume first I want my crazyflie to hover always on height 0.3 by using any commands of crazyflie_ros.. so what should I change in my crazyflie's firmware to do that?! maybe I can change the functionality in goto function? if so, what should I do? THANKS ALOT

this is goto function, maybe if I change hover_pos to setpoints that I want will let my crazyflie hover on specific height?

Code: Select all

int go_to(const struct data_go_to* data)
{
int result = 0;
if (isInGroup(data->groupMask)) {
struct vec hover_pos = mkvec(data->x, data->y, data->z);
xSemaphoreTake(lockTraj, portMAX_DELAY);
float t = usecTimestamp() / 1e6;
result = plan_go_to(&planner, data->relative, hover_pos, data->yaw, data->duration, t);
xSemaphoreGive(lockTraj);
}
return result;
}
thanks!
arnaud
Bitcraze
Posts: 2538
Joined: Tue Feb 06, 2007 12:36 pm

Re: Hovering scripts

Post by arnaud »

One basic things is that you cannot mix the crazyflie-lib-python (cflib) examples and crazyflie-ros code. These are two very different client that have different APIs. If you are using ROS you essentially cannot use anything from the crazyflie-lib-python repos. However, both cflib and Crazyflie ros uses the same firmware so you should not have to change the firmware to achieve similar functionalities.

I do not have much recent experience with ROS but I would assume that the equivalent of the motion commander (mc in examples) is relative goto commands for the movements and take-off and landing commands for the start and end of the flight. I would have assumed that take-off and sleep would achieve exactly what you want, a Crazyflie taking-off at a given height and waiting there: https://github.com/whoenig/crazyflie_ro ... py#L20-L21
RyanMco
Expert
Posts: 159
Joined: Tue Apr 09, 2019 6:15 am

Re: Hovering scripts

Post by RyanMco »

Hi ! thanks but I already tried to make just as what you said according to take off with time sleep, it wouldn't hover ! for me I put time sleep (100) after takeoff, my crazyflie truly took off to height 0.5 but land immediately .. although there's time sleep 100 .. I guess that takeoff functionality is just to let crazyflie up to height 0.5 and immediately landing although there's time sleep after takeoff but it will not keep crazyflie on the same height because takeoff is just forcing the crazyflie to immediately after reaching height 0.5 to land ..,,
RyanMco
Expert
Posts: 159
Joined: Tue Apr 09, 2019 6:15 am

Re: Hovering scripts

Post by RyanMco »

Hi arnaud, if I did update to my firmware like this:

Code: Select all

int go_to(const struct data_go_to* data)
{
int result = 0;
if (isInGroup(data->groupMask)) {
struct vec hover_pos = mkvec(data->x, data->y, data->z);
hover_pos.x=0;
hover_pos.y=0;
hover_pos.z=0.5;
xSemaphoreTake(lockTraj, portMAX_DELAY);
float t = usecTimestamp() / 1e6;
result = plan_go_to(&planner, data->relative, hover_pos, data->yaw, data->duration, t);
xSemaphoreGive(lockTraj);
}
return result;
}
will my crazyflie be hover at height 0.5m by sending goto from python script? I updated goto function and want to flash it ..
arnaud
Bitcraze
Posts: 2538
Joined: Tue Feb 06, 2007 12:36 pm

Re: Hovering scripts

Post by arnaud »

You do not have to modify the firmware, what you are trying to achieve is possible with the firmware as it is today. As far as I understand from your code you hardcoded the position setpoint when receiving a goto. Sending a goto packet with the position (0,0,0.5) should have exactly the same effect without having to modify the firmware?

It is interesting that you are getting the Crazyflie to land just after take-off, this is not the behavior I would have expected. If you send a goto after take-off, does it make the Crazyflie stay in the air?
RyanMco
Expert
Posts: 159
Joined: Tue Apr 09, 2019 6:15 am

Re: Hovering scripts

Post by RyanMco »

NOT REALLY I get shaking hovering, it's not hovering just moving like crazy
so shouldn't I do what I modified? just keep the previous situation as its? if so, then how by goto I let my crazyflie to hover on specific height?
arnaud
Bitcraze
Posts: 2538
Joined: Tue Feb 06, 2007 12:36 pm

Re: Hovering scripts

Post by arnaud »

It seems that you are having a state estimation or control issue then. Your modification and the python scripts only operates on setpoints which will only work if the state estimation and control is working correctly.

I just spin-up ROS in a VM to test and as I expected, take-off sleep land is working. The following script allowed me to get the Crazyflie to hover for 10 seconds using the flow deck:

Code: Select all

#!/usr/bin/env python

import rospy
import crazyflie
import time
import uav_trajectory

if __name__ == '__main__':
    rospy.init_node('test_high_level')

    cf = crazyflie.Crazyflie("cf1", "")

    cf.setParam("commander/enHighLevel", 1)
    cf.setParam("stabilizer/estimator", 2) # Use EKF
    cf.setParam("stabilizer/controller", 1) # Use PID controller

    cf.takeoff(targetHeight = 0.5, duration = 2.0)
    time.sleep(10)

    cf.land(targetHeight = 0.0, duration = 2.0)
    time.sleep(3.0)

A couple of note of what I modified from the original test_high_level.py script:
- I disabled the kalman reset, it should not be used if not needed.
- I used the PID controller, Mellinger works with the flow but it is not going to work if the state estimation is noisy, PID is much more forgiving (and slower...)
Post Reply