Zhehui-Huang / quad-swarm-rl

Additional environments compatible with OpenAI gym
98 stars 39 forks source link

Running the neural networks on Crazyflies #48

Open sAz-G opened 6 months ago

sAz-G commented 6 months ago

I trained a small (deepsets) neural network as suggested in this paper, and implemented the c code for calculating the output for a given input. The code should run on a Crazyflie.

I first try a simple scenario with a single drone, where I hard-code the values of the neighbor observations. The velocity of each neighbor is 0 and the neighbors are on the ground, where only the y-position varies with 1.5m jumps. In other words Vk = (0,0,0), P1 = (9.5, 0, 0), P2 = (9.5, 1.5, 0), P3 = (9.5, 3, 0)... P6 = (9.5, 7.5, 0), for k=6 neighbors. The target position of the drone is Pt = (x=0,y=0,z=1). The drone reacts to the output of the neural netwrork however it fails to fly.

When I plot the output values using the cfclient, I can see that the output of the network changes when I change the self observation values (for example if I change the yaw angle or if I change the angular velocity by moving the drone manually).

On top of debugging the code I would like to make sure that I use the output and input of the neural network properly.

Do I have to normalize the input before feeding it to the network?

What is the representation of the rotation matrix? I am currently getting the roll pitch and yaw angles from the state at the stabilizer and from these angles I calculate the rotation matrix according to the General 3D rotations equation. Where alpha is yaw, beta is pitch and gamma is the roll angle. Then I insert the entries of the rotation matrix row by row.

In which order do I have to enter the angular velocity? Currently I use this order: wx,wy,wz.

I tried to figure out the answer to each of these questions in this page.

I modified the power distribution function such that I set

motorThrustUncapped->motors.m1 = f1;
motorThrustUncapped->motors.m2 = f2;
motorThrustUncapped->motors.m3 = f3;
motorThrustUncapped->motors.m4 = f4;

fk = 0.5*(clip(ak, -1, 1) + 1), where ak is the kth output of the network.

sAz-G commented 6 months ago

I could find the answer for the input space here (I guess). I am still not sure where in the crazyflie firmware to insert the network output

AI4IS commented 1 month ago

Hi, I also have this confusion. Do you work it out? I have trained a control model. However, I have no ideas on how to run this model on a real hardware. Are there any ways to help me overcome this problem? Thanks!