-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Model output to Crazyflie Control #61
Comments
Hi! Thanks for dropping by. I don't have an end-to-end sim-train-to-real example, but I have code that shows how to interact with the crazyflie using setpoints here. The code is fairly undocumented as of now, so feel free to leave this issue open and leave questions if you want. |
ok thank you. Quick question about you the values used to train models. are all those in the global frame or body frame? Digging into the code found here: def update_state(self) -> None:
"""Updates the current state of the UAV.
This includes: ang_vel, ang_pos, lin_vel, lin_pos.
"""
lin_pos, ang_pos = self.p.getBasePositionAndOrientation(self.Id)
lin_vel, ang_vel = self.p.getBaseVelocity(self.Id)
# express vels in local frame
rotation = np.array(self.p.getMatrixFromQuaternion(ang_pos)).reshape(3, 3).T
lin_vel = np.matmul(rotation, lin_vel)
ang_vel = np.matmul(rotation, ang_vel)
# ang_pos in euler form
ang_pos = self.p.getEulerFromQuaternion(ang_pos)
# update the main body
self.body.state_update(rotation)
# create the state
self.state = np.stack([ang_vel, ang_pos, lin_vel, lin_pos], axis=0)
# update auxiliary information
self.aux_state = self.motors.get_states() it looks like the following are expressed in world/global coordinates:
And that the following are expressed in the body/local coordinates:
Is this correct? Also all of these are in radians correct? |
Yep, both of those assumptions are correct. Positions are always in global while velocities are local. |
sweet thank you, When using the default 0 mode with angular velocities, based off pybullet having things in radians, I assume the first 3 are in radians and is the T in percentage? |
Yep, that's correct. More concisely, T is in ratio, ie: 1.0 is 100% and 0.0 is 0%. |
@jjshoots so does 0 mean hover thrust or no motor power? |
0 means motor stop. You can actually input negative thrust too, in which case, the motor will spin in reverse and force and torques will be reversed. This allows us to simulate 3D drones. However, for the current quadx API, there is a motor min-throttle clip here: https://github.com/jjshoots/PyFlyt/blob/master/PyFlyt/core/drones/quadx.py#L493 |
@jjshoots ok that makes sense. I just wanted to verify. Now is there a way to vary the mass of the drone during reset? I can't seem to find anything that loads in the urdf mass for something like the hover training. |
Masses are defined in the URDF by default in pybullet. But if you want to change it during runtime, you could do something like this: https://github.com/jjshoots/PyFlyt/blob/master/PyFlyt/core/abstractions/boosters.py#L207 |
@jjshoots SO I tried your CrazyFlyt and when I connected it to the hardware with the flowdeck it just flipped on the ground and didn't really take off at all. I couldn't even get it to hover with the simple example you have. Did you do anything special to get it to work with the real hardware? |
I assume you have tried just hovering normally and verifying that it works that way? There are a number of things that could cause it to just flip, common examples are flipped props, reversed sensors, etc. I would try doing a normal flight using simple bluetooth control via the crazyflie's official implementation first. |
Hi great repo! Do you have an example using the stablebaselines3 algorithms such as PPO that controls an actual crazyflie drone? I just trained a model using the (vp, vq, vr, T) flight mode and would like to integrate into a crazyflie. I was just curious if you already had a working example.
The text was updated successfully, but these errors were encountered: