Skip to content

Commit

Permalink
Betaflight example
Browse files Browse the repository at this point in the history
  • Loading branch information
JacopoPan committed Aug 5, 2023
1 parent 827c423 commit b2f3b34
Show file tree
Hide file tree
Showing 5 changed files with 8,493 additions and 115 deletions.
27 changes: 10 additions & 17 deletions gym_pybullet_drones/assets/racer.urdf
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
<?xml version="1.0" ?>

<robot name="cf2">
<robot name="racer">

<properties arm="0.0397" kf="3.16e-10" km="7.94e-12" thrust2weight="2.25" max_speed_kmh="30" gnd_eff_coeff="11.36859" prop_radius="2.31348e-2" drag_coeff_xy="9.1785e-7" drag_coeff_z="10.311e-7" dw_coeff_1="2267.18" dw_coeff_2=".16" dw_coeff_3="-.11" />
<properties arm="0.109" kf="8.47e-9" km="2.13e-11" thrust2weight="4.17" max_speed_kmh="200" gnd_eff_coeff="11.36859" prop_radius="12.7e-2" drag_coeff_xy="9.1785e-7" drag_coeff_z="10.311e-7" dw_coeff_1="2267.18" dw_coeff_2=".16" dw_coeff_3="-.11" />

<link name="base_link">

<inertial>
<origin rpy="0 0 0" xyz="0 0 0"/>
<mass value="0.027"/>
<inertia ixx="1.4e-5" ixy="0.0" ixz="0.0" iyy="1.4e-5" iyz="0.0" izz="2.17e-5"/>
<mass value="0.830"/>
<inertia ixx=".003113" ixy="0.0" ixz="0.0" iyy=".003113" iyz="0.0" izz=".003113"/>
</inertial>

<!-- links>
<carlos url="https://arxiv.org/pdf/1608.05786.pdf" />
<julian url="https://www.research-collection.ethz.ch/handle/20.500.11850/214143" />
<mit url="http://groups.csail.mit.edu/robotics-center/public_papers/Landry15.pdf" />
</links -->

<visual>
<origin rpy="0 0 55" xyz="0 0 0"/>
<geometry>
<mesh filename="./cf2.dae" scale=" 1 1 1"/>
<mesh filename="./cf2.dae" scale="3 3 3"/>
</geometry>
<material name="grey">
<color rgba=".5 .5 .5 1"/>
Expand All @@ -39,7 +33,7 @@

<link name="prop0_link">
<inertial>
<origin rpy="0 0 0" xyz="0.028 0.028 0"/>
<origin rpy="0 0 0" xyz="0.0850 0.0675 0"/>
<mass value="0"/>
<inertia ixx="0" ixy="0" ixz="0" iyy="0" iyz="0" izz="0"/>
</inertial>
Expand All @@ -51,7 +45,7 @@

<link name="prop1_link">
<inertial>
<origin rpy="0 0 0" xyz="-0.028 0.028 0"/>
<origin rpy="0 0 0" xyz="-0.0850 0.0675 0"/>
<mass value="0"/>
<inertia ixx="0" ixy="0" ixz="0" iyy="0" iyz="0" izz="0"/>
</inertial>
Expand All @@ -63,7 +57,7 @@

<link name="prop2_link">
<inertial>
<origin rpy="0 0 0" xyz="-0.028 -0.028 0"/>
<origin rpy="0 0 0" xyz="-0.085 -0.0675 0"/>
<mass value="0"/>
<inertia ixx="0" ixy="0" ixz="0" iyy="0" iyz="0" izz="0"/>
</inertial>
Expand All @@ -75,7 +69,7 @@

<link name="prop3_link">
<inertial>
<origin rpy="0 0 0" xyz="0.028 -0.028 0"/>
<origin rpy="0 0 0" xyz="0.085 -0.0675 0"/>
<mass value="0"/>
<inertia ixx="0" ixy="0" ixz="0" iyy="0" iyz="0" izz="0"/>
</inertial>
Expand All @@ -97,5 +91,4 @@
<child link="center_of_mass_link"/>
</joint>

</robot>

</robot>
11 changes: 6 additions & 5 deletions gym_pybullet_drones/envs/BaseAviary.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,9 @@ def _physics(self,
"""
forces = np.array(rpm**2)*self.KF
torques = np.array(rpm**2)*self.KM
z_torque = (-torques[0] + torques[1] - torques[2] + torques[3]) # TODO : change this for non CW nor CCW configurations, e.g., Betaflight
if self.DRONE_MODEL == DroneModel.RACE:
torques = -torques
z_torque = (-torques[0] + torques[1] - torques[2] + torques[3])
for i in range(4):
p.applyExternalForce(self.DRONE_IDS[nth_drone],
i,
Expand Down Expand Up @@ -842,16 +844,15 @@ def _dynamics(self,
thrust_world_frame = np.dot(rotation, thrust)
force_world_frame = thrust_world_frame - np.array([0, 0, self.GRAVITY])
z_torques = np.array(rpm**2)*self.KM
if self.DRONE_MODEL == DroneModel.RACE:
z_torques = -z_torques
z_torque = (-z_torques[0] + z_torques[1] - z_torques[2] + z_torques[3])
if self.DRONE_MODEL==DroneModel.CF2X:
if self.DRONE_MODEL==DroneModel.CF2X or self.DRONE_MODEL==DroneModel.RACE:
x_torque = (forces[0] + forces[1] - forces[2] - forces[3]) * (self.L/np.sqrt(2))
y_torque = (- forces[0] + forces[1] + forces[2] - forces[3]) * (self.L/np.sqrt(2))
elif self.DRONE_MODEL==DroneModel.CF2P:
x_torque = (forces[1] - forces[3]) * self.L
y_torque = (-forces[0] + forces[2]) * self.L
if self.DRONE_MODEL==DroneModel.RACE:
x_torque = (forces[0] + forces[1] - forces[2] - forces[3]) * (self.L/np.sqrt(2))
y_torque = (- forces[0] + forces[1] + forces[2] - forces[3]) * (self.L/np.sqrt(2))
torques = np.array([x_torque, y_torque, z_torque])
torques = torques - np.cross(rpy_rates, np.dot(self.J, rpy_rates))
rpy_rates_deriv = np.dot(self.J_INV, torques)
Expand Down
Loading

0 comments on commit b2f3b34

Please sign in to comment.