lis-epfl / apg_trajectory_tracking

Training efficient drone controllers with Analytic Policy Gradient
115 stars 15 forks source link

Error in config_quad.json if parameters are modified #5

Closed abdul-mannan-khan closed 6 months ago

abdul-mannan-khan commented 9 months ago

Hello @NinaWie Thank you for this wonderful work and for sharing it. It is very interesting.

Just one question regarding config_quad.json. I tried to change parameters in this file https://github.com/lis-epfl/apg_trajectory_tracking/blob/1db5286be4ed9c3cbfffc842640ee2e87e57ec17/neural_control/dynamics/config_quad.json#L13

to crazyflie parameters such as

    "arm_length": 0.092,
    "frame_inertia": [
        0.0186,
        0.0186,
        0.0289
    ],

and

"mass": 0.034,

and the simulation animation was not working. I have made video of output animation

https://github.com/lis-epfl/apg_trajectory_tracking/assets/22067958/62cfa18e-554d-4597-b64c-f6b3c0dc0c63

Can you please guide me on what could be a possible reason for this outcome? Do I need to retune MPC, and where can I do it? Thank you for your help.

NinaWie commented 9 months ago

Hi @abdul-mannan-khan , thanks for your interest in our work! Unfortunately, I can't play the video because I see the error "file is corrupt". Could you also give some more information about what script you are running? You can test our APG appraoch with a pretrained neural network (not MPC) by running python scripts/evaluate_drone.py --animate. If you want to use MPC instead of our simulation, you need to use python scripts/evaluate_drone.py --animate -m mpc. By default, this script is using the default quadrotor parameters. To test the robustness of the model to changed conditions (zero-shot), we specified a dictionary modified_parameters here in the code. Hope this already clarifies some things; please let me know what went wrong with the simulation.

abdul-mannan-khan commented 9 months ago

Hello @NinaWie Thank you for your response. Appologies for not fllowing up. I see that we can change the parameters in file as you mentioned here. However, I am trying to change parameters for which system can be trained in apg_trajectory_tracking/neural_control/dynamics/config_quad.json. Can you please comment on how can I change drone parameters so that it trained with given parameters? Thank you so much for your prompt response.

vwueest commented 9 months ago

Hey @abdul-mannan-khan, I replicated your issue and found that we had hard-coded the quadrotor mass in one of the quadrotor dynamics files. I corrected it (https://github.com/lis-epfl/apg_trajectory_tracking/commit/22ca4dabf5b823f4168bfcebc91a0cbe06261d69). Please try pulling the main branch and try again. For me it worked with the mass / inertias that you wanted to try

abdul-mannan-khan commented 8 months ago

Hey @vwueest Thank you for fixing this error. I am trying to run it now, and I will update you once it works. I am so grateful to you.

abdul-mannan-khan commented 8 months ago

Hello @vwueest,

I hope you're having a delightful Christmas holiday season. I am currently working on a simulation project and attempting to apply it to a different drone model. I've used the configuration from config_crazyflie.json, but unfortunately, I'm encountering some issues.

I maintained the original settings, but the results weren't as expected:

Epoch 399
Loss (controller): 903.44
Data used for training: 798000

I have also recorded a video of the simulation output for better clarity, which you can view here: Simulation Output Video.

Later, I ran it for 1000 epochs, and here is the response I got:

Epoch 999
Loss (controller): 1006.62
Data used for training: 1998000

As you can see, the controller loss is almost the same, which shows that there is no significant improvement in the controller output.

Next, I tried running following command:

python scripts/evaluate_drone.py -a 50

and here is the output I got:

/home/yf23868/anaconda3/envs/scaramuzza_env/lib/python3.8/site-packages/numpy/core/fromnumeric.py:3464: RuntimeWarning: Mean of empty slice.
  return _methods._mean(a, axis=axis, dtype=dtype,
/home/yf23868/anaconda3/envs/scaramuzza_env/lib/python3.8/site-packages/numpy/core/_methods.py:192: RuntimeWarning: invalid value encountered in scalar divide
  ret = ret.dtype.type(ret / rcount)
/home/yf23868/anaconda3/envs/scaramuzza_env/lib/python3.8/site-packages/numpy/core/_methods.py:269: RuntimeWarning: Degrees of freedom <= 0 for slice
  ret = _var(a, axis=axis, dtype=dtype, out=out, ddof=ddof,
/home/yf23868/anaconda3/envs/scaramuzza_env/lib/python3.8/site-packages/numpy/core/_methods.py:226: RuntimeWarning: invalid value encountered in divide
  arrmean = um.true_divide(arrmean, div, out=arrmean,
/home/yf23868/anaconda3/envs/scaramuzza_env/lib/python3.8/site-packages/numpy/core/_methods.py:261: RuntimeWarning: invalid value encountered in scalar divide
  ret = ret.dtype.type(ret / rcount)
rand: Average div of full runs: nan (nan)
Ratio of stable runs: 0.00

However, with the original drone model, I do not see such a problem, and it works fine. I have tested it even for 200 epochs, and it works fine. Could you please advise on the adjustments needed for the drone to accurately follow the intended trajectory? Any guidance or suggestions you can provide would be immensely appreciated. Thank you in advance for your help!

abdul-mannan-khan commented 8 months ago

Hello @vwueest I solved this problem. The problem was in the config_quad.json file. I updated the parameters as follows:

{
    "mass": 0.034,
    "rotational_drag": [
        0,
        0,
        0
    ],
    "translational_drag": [
        0,
        0,
        0
    ],
    "arm_length": 0.31,
    "frame_inertia": [
        0.0186,
        0.0186,
        0.0289
    ],
    "gravity": [
        0,
        0,
        -9.81
    ],
    "kinv_ang_vel_tau": [
        16.6, 
        16.6, 
        5.0
    ]
}

and it worked. I noticed that the simulation does not work for smaller values in kinv_ang_vel_tau as follows:

    "kinv_ang_vel_tau": [
        0.06875,
        0.06875,
        0.02071
    ]

can you please tell me what it is? Thank you.