Skip to content
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

Adds Multi-body dynamics primarily #141

Open
wants to merge 63 commits into
base: v1.0.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
597c835
Implemented scaling down parameter
AhmadAmine998 Aug 4, 2024
c625963
Add pyqt rendering skeleton code
AhmadAmine998 Aug 5, 2024
8ddc384
Add pyqt objects skeleton code
AhmadAmine998 Aug 5, 2024
9e709c5
Implement render lines and closed lines
AhmadAmine998 Aug 5, 2024
abf0b66
Implement pyqt TextObject
AhmadAmine998 Aug 5, 2024
afa7e59
Deprecate pyqt Map object
AhmadAmine998 Aug 5, 2024
2214094
Initial implementation of PyQt Car object
AhmadAmine998 Aug 5, 2024
d984495
Make update of car consistent with env renderer
AhmadAmine998 Aug 5, 2024
9f97e98
Update pyqt text object rendering to be consistent with env renderer
AhmadAmine998 Aug 5, 2024
75fba6f
Initial implementation of env renderer render
AhmadAmine998 Aug 5, 2024
448031e
Fix initialization of TextObject
AhmadAmine998 Aug 5, 2024
b997e53
Initial implementation of EnvRender init
AhmadAmine998 Aug 5, 2024
e255bea
Disable default mouse interactions for plot
AhmadAmine998 Aug 5, 2024
b051635
Update render callbacks to update waypoints instead of redrawing
AhmadAmine998 Aug 5, 2024
ddacb8a
Fix issue with jagged lines in rendering
AhmadAmine998 Aug 6, 2024
e8154e6
Now renders cars correctly
AhmadAmine998 Aug 6, 2024
166f0a5
Implement scaled and translated image for proper plotting
AhmadAmine998 Aug 6, 2024
eb95c96
Added wheels
AhmadAmine998 Aug 6, 2024
c12bf0b
Bugfix wheel orientation
AhmadAmine998 Aug 6, 2024
b364741
minor fixes
AhmadAmine998 Aug 6, 2024
1340029
Implement focus and mouse click callbacks
AhmadAmine998 Aug 6, 2024
450ea14
Implement keyboard press event handle
AhmadAmine998 Aug 6, 2024
9e39cbb
Add rendering yaml toggle to switch rendering types
AhmadAmine998 Aug 6, 2024
a2bdc82
Merge branch 'dev-qtgraph-rendering' into dev-model-scale
AhmadAmine998 Aug 6, 2024
989f8a8
Fixed rendering of scaled track, works only for pyqt6 rendering
AhmadAmine998 Aug 6, 2024
1da98e9
Merge branch 'v1.0.0' into dev-qtgraph-rendering
AhmadAmine998 Aug 6, 2024
d8a3a45
Add qt as dependency. Fix render_points
AhmadAmine998 Aug 6, 2024
719465a
Typo in toml
AhmadAmine998 Aug 6, 2024
e476f6d
Merge branch 'dev-qtgraph-rendering' into dev-model-scale
AhmadAmine998 Aug 9, 2024
35c3125
Fix wrong scan simulator resolution
AhmadAmine998 Aug 9, 2024
78591eb
Implemented rgb_array mode for rqt6
AhmadAmine998 Aug 9, 2024
690daa9
Updated ST model
nandantumu Sep 21, 2024
0fe5f53
Updated locked dependencies
nandantumu Sep 21, 2024
d3d181a
Refactored dynamics into a module
nandantumu Sep 21, 2024
38b6fe4
Refactored dynamics into a module
nandantumu Sep 21, 2024
13970c3
Replaced pyproject.toml
nandantumu Sep 21, 2024
3d19862
Merge remote-tracking branch 'origin/dev-model-scale' into dev-dynamics
nandantumu Sep 21, 2024
45a2816
Fixed errors so tests run.
nandantumu Sep 21, 2024
3052c43
Updated so KeyboardInterrupt does not segfault on macOS
nandantumu Sep 21, 2024
4c9a5b9
Fixed typing error
nandantumu Sep 21, 2024
b1856c5
Working MB commit
nandantumu Sep 23, 2024
9b173e6
Updated speed and kinematic threshold for numerical stability.
nandantumu Sep 23, 2024
dc91a46
Updated dynamics tests
nandantumu Sep 23, 2024
cea4ea3
Fully working MB model
nandantumu Sep 24, 2024
ab7a6ec
Attempted speed optimization.
nandantumu Sep 24, 2024
0348928
Fix rendering of tires to be correct
AhmadAmine998 Sep 24, 2024
00e268d
Removing keepalive from example
nandantumu Sep 24, 2024
0e41aa3
Merge branch 'dev-qtgraph-rendering' into dev-model-scale
AhmadAmine998 Sep 27, 2024
c782fb4
Updated observations for futher compatibility.
nandantumu Sep 27, 2024
78e394e
Add scale to default_dict. Fix setting scale
AhmadAmine998 Sep 28, 2024
74435ed
Qt rgb is rendering now returns rgb no alpha
AhmadAmine998 Sep 28, 2024
33c9d3d
Renders car and callbacks in rgb mode
AhmadAmine998 Sep 28, 2024
339a5b8
Update ci to install qt dependencies and make qt headless
AhmadAmine998 Sep 30, 2024
1dfd648
Replace export in CI with variables
AhmadAmine998 Oct 1, 2024
cb7455b
Switch to env in ci
AhmadAmine998 Oct 1, 2024
75e62f1
Instantiate QApp for rgb_array_list test
AhmadAmine998 Oct 1, 2024
f2dcf44
Merge branch 'v1.0.0' into dev-qtgraph-rendering
AhmadAmine998 Oct 1, 2024
9f022c2
Merge branch 'dev-qtgraph-rendering' into dev-model-scale
AhmadAmine998 Oct 1, 2024
a62c9d8
Merge branch 'dev-model-scale' into dev-dynamics
AhmadAmine998 Oct 2, 2024
de44270
Update dynamics to use arctan. Update tests to use func_KS, func_ST
AhmadAmine998 Sep 27, 2024
dfe00de
Fix test to correct calls of func_KS/ST
AhmadAmine998 Oct 2, 2024
67d72cf
Set environment variable
nandantumu Oct 2, 2024
967e1aa
Fixing last commit
nandantumu Oct 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,20 @@ permissions:

jobs:
build:

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]
# env:
# QT_QPA_PLATFORM: offscreen

steps:
- name: Update apt
run: sudo apt update

- name: Install openGL
run: sudo apt install freeglut3-dev
run: sudo apt install -y freeglut3-dev libglib2.0-0 libsm6 libxrender1 libxext6 libxkbcommon-x11-0 libdbus-1-dev

- uses: actions/checkout@v2

Expand Down
49 changes: 39 additions & 10 deletions examples/waypoint_follow.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import numpy as np
from numba import njit

from f1tenth_gym.envs.f110_env import F110Env

"""
Planner Helpers
Expand Down Expand Up @@ -187,6 +188,9 @@ def __init__(self, track, wb):
self.lookahead_point = None
self.current_index = None

self.lookahead_point_render = None
self.local_plan_render = None

def load_waypoints(self, conf):
"""
loads waypoints
Expand All @@ -201,16 +205,26 @@ def render_lookahead_point(self, e):
Callback to render the lookahead point.
"""
if self.lookahead_point is not None:
points = self.lookahead_point[:2][None] # shape (1, 2)
e.render_points(points, color=(0, 0, 128), size=2)
points = self.lookahead_point[:2][None] # shape (1, 2)~
if self.lookahead_point_render is None:
self.lookahead_point_render = e.render_points(
points, color=(0, 0, 128), size=2
)
else:
self.lookahead_point_render.setData(points)

def render_local_plan(self, e):
"""
update waypoints being drawn by EnvRenderer
"""
if self.current_index is not None:
points = self.waypoints[self.current_index : self.current_index + 10, :2]
e.render_lines(points, color=(0, 128, 0), size=1)
if self.local_plan_render is None:
self.local_plan_render = e.render_lines(
points, color=(0, 128, 0), size=1
)
else:
self.local_plan_render.updateItems(points)

def _get_current_waypoint(
self, waypoints, lookahead_distance, position, theta
Expand Down Expand Up @@ -287,11 +301,11 @@ def main():
work = {
"mass": 3.463388126201571,
"lf": 0.15597534362552312,
"tlad": 0.82461887897713965,
"vgain": 1,
"tlad": 0.82461887897713965 * 10,
"vgain": 1.0,
}

num_agents = 3
num_agents = 1
env = gym.make(
"f1tenth_gym:f1tenth-v0",
config={
Expand All @@ -300,16 +314,23 @@ def main():
"timestep": 0.01,
"integrator": "rk4",
"control_input": ["speed", "steering_angle"],
"model": "st",
"model": "mb",
"observation_config": {"type": "kinematic_state"},
"params": {"mu": 1.0},
"params": F110Env.fullscale_vehicle_params(),
"reset_config": {"type": "rl_random_static"},
"scale": 10.0,
},
render_mode="human",
)
track = env.unwrapped.track

planner = PurePursuitPlanner(track=track, wb=0.17145 + 0.15875)
planner = PurePursuitPlanner(
track=track,
wb=(
F110Env.fullscale_vehicle_params()["lf"]
+ F110Env.fullscale_vehicle_params()["lr"]
),
)

env.unwrapped.add_render_callback(track.raceline.render_waypoints)
env.unwrapped.add_render_callback(planner.render_local_plan)
Expand All @@ -333,7 +354,6 @@ def main():
work["vgain"],
)
action[i] = np.array([steer, speed])

obs, step_reward, done, truncated, info = env.step(action)
laptime += step_reward
frame = env.render()
Expand All @@ -343,3 +363,12 @@ def main():

if __name__ == "__main__":
main()
# %%
work = {
"mass": 3.463388126201571,
"lf": 0.15597534362552312,
"tlad": 0.82461887897713965 * 10,
"vgain": 1,
}

num_agents = 1
32 changes: 23 additions & 9 deletions f1tenth_gym/envs/base_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@
Replacement of the old RaceCar, Simulator classes in C++
Author: Hongrui Zheng
"""

from __future__ import annotations
import numpy as np
from .dynamic_models import DynamicModel
from .action import CarAction
from .collision_models import collision_multiple, get_vertices
from .integrator import EulerIntegrator, IntegratorType
from .integrator import EulerIntegrator, Integrator
from .laser_models import ScanSimulator2D, check_ttc_jit, ray_cast
from .track import Track

Expand Down Expand Up @@ -101,9 +102,10 @@ def __init__(
self.integrator = integrator
self.action_type = action_type
self.model = model
self.standard_state_fn = self.model.get_standardized_state_fn()

# state of the vehicle
self.state = self.model.get_initial_state()
self.state = self.model.get_initial_state(params=self.params)

# pose of opponents in the world
self.opp_poses = None
Expand Down Expand Up @@ -178,14 +180,15 @@ def update_params(self, params):
"""
self.params = params

def set_map(self, map: str | Track):
def set_map(self, map: str | Track, map_scale: float = 1.0):
"""
Sets the map for scan simulator

Args:
map (str | Track): name of the map, or Track object
map_scale (float, default=1.0): scale of the map, larger scale means larger map
"""
RaceCar.scan_simulator.set_map(map)
RaceCar.scan_simulator.set_map(map, map_scale)

def reset(self, pose):
"""
Expand All @@ -203,7 +206,7 @@ def reset(self, pose):
# clear collision indicator
self.in_collision = False
# init state from pose
self.state = self.model.get_initial_state(pose=pose)
self.state = self.model.get_initial_state(pose=pose, params=self.params)

self.steer_buffer = np.empty((0,))
# reset scan random generator
Expand Down Expand Up @@ -310,7 +313,7 @@ def update_pose(self, raw_steer, vel):
)

# bound yaw angle
self.state[4] %= 2 * np.pi
self.state[4] %= 2 * np.pi # TODO: This is a problem waiting to happen

# update scan
current_scan = RaceCar.scan_simulator.scan(
Expand Down Expand Up @@ -354,6 +357,16 @@ def update_scan(self, agent_scans, agent_index):

agent_scans[agent_index] = new_scan

@property
def standard_state(self) -> dict:
"""
Returns the state of the vehicle as an observation

Returns:
np.ndarray (7, ): state of the vehicle
"""
return self.standard_state_fn(self.state)


class Simulator(object):
"""
Expand All @@ -379,7 +392,7 @@ def __init__(
num_agents,
seed,
action_type: CarAction,
integrator=IntegratorType.RK4,
integrator=Integrator,
model=DynamicModel.ST,
time_step=0.01,
ego_idx=0,
Expand Down Expand Up @@ -428,18 +441,19 @@ def __init__(
num_beams = self.agents[0].scan_simulator.num_beams
self.agent_scans = np.empty((self.num_agents, num_beams))

def set_map(self, map: str | Track):
def set_map(self, map: str | Track, map_scale: float = 1.0):
"""
Sets the map of the environment and sets the map for scan simulator of each agent

Args:
map (str | Track): name of the map, or Track object
map_scale (float, default=1.0): scale of the map, larger scale means larger map

Returns:
None
"""
for agent in self.agents:
agent.set_map(map)
agent.set_map(map, map_scale)

def update_params(self, params, agent_idx=-1):
"""
Expand Down
Loading
Loading