Skip to content

Commit

Permalink
docs: Docs for PolyPositionDroneEnv
Browse files Browse the repository at this point in the history
  • Loading branch information
iwishiwasaneagle committed Mar 2, 2023
1 parent aa0e1e3 commit 95d28d0
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions src/jdrones/envs/position.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from jdrones.envs.lqr import LQRDroneEnv
from jdrones.trajectory import QuinticPolynomialTrajectory
from jdrones.types import PositionAction
from loguru import logger


class BasePositionDroneEnv(gymnasium.Env, abc.ABC):
Expand Down Expand Up @@ -135,14 +134,22 @@ def get_reward(states: States) -> float:


class PolyPositionDroneEnv(BasePositionDroneEnv):
"""
Uses :class:`jdrones.trajectory.QuinticPolynomialTrajectory` to give target
position and velocity commands at every time point until the target is reached.
If the time taken exceeds :math:`T`, the original target position is given as a raw
input as in :class:`~jdrones.envs.position.LQRPositionDroneEnv`. However, if this
were to happen, the distance is small enough to ensure stability.
"""

def step(
self, action: PositionAction
) -> tuple[States, float, bool, bool, dict[str, Any]]:
action_as_state = State()
action_as_state.pos = action

observations = collections.deque()
traj = self.calc_traj(self.env.state, action_as_state)
traj = self.calc_traj(self.env.state, action_as_state, self.model.max_vel_ms)

u: State = action_as_state.copy()

Expand Down Expand Up @@ -176,11 +183,32 @@ def step(
def calc_traj(
cur: State, tgt: State, max_vel: float = 1
) -> QuinticPolynomialTrajectory:
logger.debug(f"Generating polynomial trajectory from {cur.pos} to {tgt.pos}")
"""
Calculate the trajectory for the drone to traverse.
Total time to traverse the polynomial is defined as
.. math::
T = \\frac{||x_{t=T}-x_{t=0}||}{v_\\max}
to ensure dynamic compatibility.
Parameters
----------
cur : jdrones.data_models.State
Current state
tgt : jdrones.data_models.State
Target state
max_vel : float
Maximum vehicle velocity
Returns
-------
jdrones.trajectory.QuinticPolynomialTrajectory
The solved trajectory
"""
dist = np.linalg.norm(tgt.pos - cur.pos)
T = dist / max_vel
logger.debug(f"Total time for polynomial is {T=:.2f}s")

t = QuinticPolynomialTrajectory(
start_pos=cur.pos,
Expand Down

0 comments on commit 95d28d0

Please sign in to comment.