Skip to content

Commit

Permalink
fix lidar (#531)
Browse files Browse the repository at this point in the history
  • Loading branch information
QuanyiLi committed Aug 23, 2021
1 parent e7ab12c commit 33890e9
Show file tree
Hide file tree
Showing 12 changed files with 309 additions and 63 deletions.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pgdrive/assets/models/barrier/lambert1_normal.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pgdrive/assets/models/barrier/scene.bin
Binary file not shown.
200 changes: 200 additions & 0 deletions pgdrive/assets/models/barrier/scene.gltf
@@ -0,0 +1,200 @@
{
"asset" : {
"generator" : "Khronos glTF Blender I/O v1.6.16",
"version" : "2.0"
},
"scene" : 0,
"scenes" : [
{
"name" : "Scene",
"nodes" : [
4
]
}
],
"nodes" : [
{
"mesh" : 0,
"name" : "defaultMaterial"
},
{
"children" : [
0
],
"name" : "pCube6"
},
{
"children" : [
1
],
"name" : "Collada visual scene group",
"rotation" : [
0.7071068286895752,
0,
0,
0.7071068286895752
]
},
{
"children" : [
2
],
"name" : "RootNode (model correction matrix)"
},
{
"children" : [
3
],
"name" : "RootNode (gltf orientation matrix)",
"rotation" : [
-0.7071068286895752,
0,
0,
0.7071068286895752
],
"scale" : [
1.099050760269165,
1.099050760269165,
1.099050760269165
]
}
],
"materials" : [
{
"alphaMode" : "BLEND",
"doubleSided" : true,
"name" : "lambert1.001",
"normalTexture" : {
"index" : 0
},
"occlusionTexture" : {
"index" : 1
},
"pbrMetallicRoughness" : {
"baseColorTexture" : {
"index" : 2
},
"metallicRoughnessTexture" : {
"index" : 1
}
}
}
],
"meshes" : [
{
"name" : "defaultMaterial.001",
"primitives" : [
{
"attributes" : {
"POSITION" : 0,
"NORMAL" : 1,
"TEXCOORD_0" : 2
},
"indices" : 3,
"material" : 0
}
]
}
],
"textures" : [
{
"sampler" : 0,
"source" : 0
},
{
"sampler" : 0,
"source" : 1
},
{
"sampler" : 0,
"source" : 2
}
],
"images" : [
{
"mimeType" : "image/png",
"name" : "lambert1_normal",
"uri" : "lambert1_normal.png"
},
{
"mimeType" : "image/png",
"name" : "lambert1_metallicRoughness",
"uri" : "lambert1_metallicRoughness.png"
},
{
"mimeType" : "image/png",
"name" : "lambert1_baseColor",
"uri" : "lambert1_baseColor.png"
}
],
"accessors" : [
{
"bufferView" : 0,
"componentType" : 5126,
"count" : 1113,
"max" : [
0.9164959788322449,
1,
0.4118080139160156
],
"min" : [
-0.9164959788322449,
-1,
-0.4118080139160156
],
"type" : "VEC3"
},
{
"bufferView" : 1,
"componentType" : 5126,
"count" : 1113,
"type" : "VEC3"
},
{
"bufferView" : 2,
"componentType" : 5126,
"count" : 1113,
"type" : "VEC2"
},
{
"bufferView" : 3,
"componentType" : 5123,
"count" : 2172,
"type" : "SCALAR"
}
],
"bufferViews" : [
{
"buffer" : 0,
"byteLength" : 13356,
"byteOffset" : 0
},
{
"buffer" : 0,
"byteLength" : 13356,
"byteOffset" : 13356
},
{
"buffer" : 0,
"byteLength" : 8904,
"byteOffset" : 26712
},
{
"buffer" : 0,
"byteLength" : 4344,
"byteOffset" : 35616
}
],
"samplers" : [
{
"magFilter" : 9729,
"minFilter" : 9987
}
],
"buffers" : [
{
"byteLength" : 39960,
"uri" : "scene.bin"
}
]
}
44 changes: 32 additions & 12 deletions pgdrive/component/static_object/traffic_object.py
@@ -1,12 +1,10 @@
from typing import Tuple
from pgdrive.constants import CollisionGroup

import numpy as np
from panda3d.bullet import BulletBoxShape
from panda3d.bullet import BulletCylinderShape
from panda3d.core import NodePath

from pgdrive.component.static_object.base_static_object import BaseStaticObject
from pgdrive.constants import BodyName
from pgdrive.constants import CollisionGroup
from pgdrive.engine.asset_loader import AssetLoader
from pgdrive.engine.physics_node import BaseRigidBodyNode
from pgdrive.utils.coordinates_shift import panda_position, panda_heading
Expand All @@ -18,10 +16,7 @@ class TrafficObject(BaseStaticObject):
"""
Common interface for objects that appear on the road, beside vehicles.
"""
NAME = None
RADIUS = 0.25
HEIGHT = 1.2
MASS = 1
NAME = BodyName.Traffic_object
COLLISION_GROUP = CollisionGroup.TrafficObject

COST_ONCE = True # cost will give at the first time
Expand All @@ -42,7 +37,9 @@ def __init__(self, lane, longitude: float, lateral: float, random_seed):
class TrafficCone(TrafficObject):
"""Placed near the construction section to indicate that traffic is prohibited"""

NAME = BodyName.Traffic_cone
RADIUS = 0.25
HEIGHT = 1.2
MASS = 1

def __init__(self, lane, longitude: float, lateral: float, static: bool = False, random_seed=None):
super(TrafficCone, self).__init__(lane, longitude, lateral, random_seed)
Expand All @@ -59,14 +56,15 @@ def __init__(self, lane, longitude: float, lateral: float, static: bool = False,
self.set_static(static)


class TrafficTriangle(TrafficObject):
class TrafficWarning(TrafficObject):
"""Placed behind the vehicle when it breaks down"""

NAME = BodyName.Traffic_triangle
HEIGHT = 1.2
MASS = 1
RADIUS = 0.5

def __init__(self, lane, longitude: float, lateral: float, static: bool = False, random_seed=None):
super(TrafficTriangle, self).__init__(lane, longitude, lateral, random_seed)
super(TrafficWarning, self).__init__(lane, longitude, lateral, random_seed)
self.add_body(BaseRigidBodyNode(self.name, self.NAME))
self.body.addShape(BulletCylinderShape(self.RADIUS, self.HEIGHT))
self.body.setIntoCollideMask(self.COLLISION_GROUP)
Expand All @@ -79,3 +77,25 @@ def __init__(self, lane, longitude: float, lateral: float, static: bool = False,
model.setPos(0, 0, -self.HEIGHT / 2)
model.reparentTo(self.origin)
self.set_static(static)


class TrafficBarrier(TrafficObject):
"""A barrier"""

HEIGHT = 2.0
MASS = 10
LENGTH = 2.0
WIDTH = 0.3

def __init__(self, lane, longitude: float, lateral: float, static: bool = False, random_seed=None):
super(TrafficBarrier, self).__init__(lane, longitude, lateral, random_seed)
self.add_body(BaseRigidBodyNode(self.name, self.NAME))
self.body.addShape(BulletBoxShape((self.WIDTH / 2, self.LENGTH / 2, self.HEIGHT / 2)))
self.body.setIntoCollideMask(self.COLLISION_GROUP)
self.origin.setPos(panda_position(self.position, self.HEIGHT / 2))
self.origin.setH(panda_heading(self.heading))
if self.render:
model = self.loader.loadModel(AssetLoader.file_path("models", "barrier", "scene.gltf"))
model.setH(-90)
model.reparentTo(self.origin)
self.set_static(static)
2 changes: 1 addition & 1 deletion pgdrive/component/vehicle_module/lidar.py
Expand Up @@ -23,7 +23,7 @@ class Lidar(DistanceDetector):
def __init__(self, num_lasers: int = 240, distance: float = 50, enable_show=False):
super(Lidar, self).__init__(num_lasers, distance, enable_show)
self.origin.hide(CamMask.RgbCam | CamMask.Shadow | CamMask.Shadow | CamMask.DepthCam)
self.mask = CollisionGroup.Vehicle | CollisionGroup.InvisibleWall
self.mask = CollisionGroup.Vehicle | CollisionGroup.InvisibleWall | CollisionGroup.TrafficObject

# lidar can calculate the detector mask by itself
self.angle_delta = 360 / num_lasers if num_lasers > 0 else None
Expand Down
6 changes: 2 additions & 4 deletions pgdrive/constants.py
Expand Up @@ -59,8 +59,7 @@ class BodyName:
InvisibleWall = "InvisibleWall"
Vehicle = "Vehicle"
Lane = "Lane"
Traffic_cone = "Traffic Cone"
Traffic_triangle = "Traffic Triangle"
Traffic_object = "Traffic Object"
TollGate = "Toll Gate"


Expand All @@ -70,8 +69,7 @@ class BodyName:
BodyName.Yellow_continuous_line: "red",
BodyName.Broken_line: "yellow",
BodyName.Vehicle: "red",
BodyName.Traffic_cone: "orange",
BodyName.Traffic_triangle: "orange",
BodyName.Traffic_object: "orange",
BodyName.InvisibleWall: "red",
BodyName.TollGate: "red",
}
Expand Down
2 changes: 1 addition & 1 deletion pgdrive/engine/core/collision_callback.py
Expand Up @@ -25,7 +25,7 @@ def collision_callback(contact):
if another_node_name == BodyName.Vehicle:
obj_1.crash_vehicle = True
# crash objects
elif another_node_name in [BodyName.Traffic_cone, BodyName.Traffic_triangle]:
elif another_node_name == BodyName.Traffic_object:
if not obj_2.crashed:
obj_1.crash_object = True
if obj_2.COST_ONCE:
Expand Down

0 comments on commit 33890e9

Please sign in to comment.