Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Gamenot committed Apr 17, 2023
1 parent d08cea6 commit 1df5d88
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
7 changes: 5 additions & 2 deletions smarts/bullet/bullet_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# THE SOFTWARE.
import importlib.resources as pkg_resources
import os
from typing import Any
from typing import Any, Optional

from smarts.bullet import pybullet
from smarts.bullet.pybullet import bullet_client as bc
Expand Down Expand Up @@ -124,7 +124,10 @@ def initialize_ground(self, resource_path, map_bb):
)

def step(
self, dt: float, simulation_frame: SimulationFrame, vehicle_index: VehicleIndex
self,
dt: float,
simulation_frame: Optional[SimulationFrame],
vehicle_index: VehicleIndex,
):
self._bullet_client.stepSimulation()
pybullet_substeps = max(1, round(dt / self._pybullet_period)) - 1
Expand Down
7 changes: 5 additions & 2 deletions smarts/core/physics/physics_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
from typing import Any
from typing import Any, Optional

from smarts.core.coordinates import BoundingBox
from smarts.core.simulation_frame import SimulationFrame
Expand Down Expand Up @@ -56,7 +56,10 @@ def teardown(self):
raise NotImplementedError

def step(
self, dt: float, simulation_frame: SimulationFrame, vehicle_index: VehicleIndex
self,
dt: float,
simulation_frame: Optional[SimulationFrame],
vehicle_index: VehicleIndex,
):
"""Step the current physics simulation.
Expand Down
9 changes: 5 additions & 4 deletions smarts/core/tests/test_collision.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from smarts.core.smarts import SMARTS
from smarts.core.sumo_traffic_simulation import SumoTrafficSimulation
from smarts.core.vehicle import VEHICLE_CONFIGS
from smarts.core.vehicle_index import VehicleIndex
from smarts.sstudio import gen_scenario
from smarts.sstudio import types as t

Expand All @@ -63,7 +64,7 @@ def step_with_vehicle_commands(
collisions = []
for _ in range(steps):
bv.control(throttle, brake, steering)
bullet_simulation.step()
bullet_simulation.step(time_step, None, vehicle_index=VehicleIndex.identity())
collisions.extend(bv.contact_points)
return collisions

Expand All @@ -80,7 +81,7 @@ def step_with_pose_delta(
cur_pose = bv.pose
new_pose = Pose.from_center(cur_pose.position + pose_delta, cur_pose.heading)
bv.control(new_pose, speed)
bullet_simulation.step()
bullet_simulation.step(time_step, None, VehicleIndex.identity())
collisions.extend(bv.contact_points)
return collisions

Expand All @@ -99,7 +100,7 @@ def test_collision(bullet_simulation: BulletSimulation):
bullet_client=bullet_simulation.client,
)

collisions = step_with_vehicle_commands(chassis, steps=2)
collisions = step_with_vehicle_commands(chassis, bullet_simulation, steps=2)
assert len(collisions) > 0
collided_bullet_ids = set([c.bullet_id for c in collisions])
GROUND_ID = 0
Expand Down Expand Up @@ -199,7 +200,7 @@ def _joust(
for _ in range(steps):
wkc.control(throttle)
bkc.control(throttle)
bullet_simulation.step()
bullet_simulation.step(time_step, None, VehicleIndex.identity())
collisions[0].extend(wkc.contact_points)
collisions[1].extend(bkc.contact_points)
return collisions
Expand Down
4 changes: 1 addition & 3 deletions smarts/core/tests/test_trajectory_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,5 @@ def step_with_vehicle_commands(
def test_trajectory_tracking(
bullet_simulation: BulletSimulation, vehicle, radius, omega
):
final_error = step_with_vehicle_commands(
bullet_simulation.client, vehicle, radius, omega
)
final_error = step_with_vehicle_commands(bullet_simulation, vehicle, radius, omega)
assert final_error <= 10

0 comments on commit 1df5d88

Please sign in to comment.