Beispiel #1
0
def setup_scene(i: int):

    snake = Snake(NUM_SNAKE_MODULES, pitch_only=False,
                  with_camera=True)  # type: Snake
    snake.setPosition(agx.Vec3(0, 0, 0.1))
    snakeapp.add(snake)

    plane_body = agx.RigidBody(
        agxCollide.Geometry(agxCollide.Box(2, 2, 0.1),
                            agx.AffineMatrix4x4.translate(0, 0, -0.1 / 2)))

    plane_body.setMotionControl(agx.RigidBody.STATIC)
    snakeapp.create_visual(plane_body, diffuse_color=agxRender.Color.Green())
    snakeapp.add(plane_body)

    snake_controller = SnakeControl(snake)

    if i == FLAPPING:
        snake_controller.init_flapping(math.pi / 9.0, math.pi / 9.0, 16.0,
                                       -math.pi * 5.0 / 180.0)
    elif i == TURNING:
        snake_controller.init_turning(math.pi / 9.0, math.pi * 2.0 / 3.0, 8.0,
                                      0.0, math.pi * 20.0 / 180.0)
    elif i == SIDEWINDING:
        snake_controller.init_sidewinding(math.pi / 9.0, math.pi * 2.0 / 3.0,
                                          16.0)
    elif i == ROLLING:
        snake_controller.init_rolling(math.pi / 6.0, math.pi / 6.0, 16.0)
    elif i == ROTATING:
        snake_controller.init_rotating(math.pi / 6.0, math.pi / 6.0, 16.0)

    snakeapp.add_event_listener(snake_controller)

    snakeapp.init_camera(eye=agx.Vec3(-1, -1, 0.5),
                         center=plane_body.getPosition())
    def __init__(self, material: agx.Material = None):
        super().__init__()

        visual_geometry = agxCollide.Geometry(intermediate_shape.deepCopy(),
                                              agx.AffineMatrix4x4.rotate(math.pi / 2, 0, 1, 0) *
                                              agx.AffineMatrix4x4.rotate(math.pi, 1, 0, 0))
        visual_geometry.setEnableCollisions(False)
        snakeapp.create_visual(visual_geometry, agxRender.Color.Orange())

        collision_geometry = agxCollide.Geometry(agxCollide.Box(intermediate_bounds),
                                                 agx.AffineMatrix4x4.translate(intermediate_len / 2, 0, 0))

        self.body = agx.RigidBody()
        self.body.add(visual_geometry)
        self.body.add(collision_geometry)
        self.add(self.body)

        sensor_geometry = agxCollide.Geometry(agxCollide.Box(sensor_bounds),
                                              agx.AffineMatrix4x4.translate(intermediate_len / 2, -0.035, 0))
        self.sensor = agx.RigidBody(sensor_geometry)
        self.add(self.sensor)

        if material is not None:
            collision_geometry.setMaterial(material)
            sensor_geometry.setMaterial(material)

        self.merged_body = agx.MergedBody()
        self.merged_body.add(agx.MergedBodyEmptyEdgeInteraction(self.body, self.sensor))
        snakeapp.add(self.merged_body)
    def __init__(self):
        super().__init__()

        upper_geometry = agxCollide.Geometry(upper_shape.deepCopy())
        upper_geometry.setEnableCollisions(False)
        snakeapp.create_visual(upper_geometry, agxRender.Color.Black())

        self.add(upper_geometry)
Beispiel #4
0
def create_slope() -> agx.RigidBody:
    slope_body = agx.RigidBody(agxCollide.Geometry(agxCollide.Box(1, 1, 0.05)))
    snakeapp.create_visual(slope_body, diffuse_color=Color.Red())
    # slope_body.setPosition(agx.Vec3(0, 0, 0))
    slope_body.setRotation(agx.EulerAngles(0, -math.radians(slope_angle),
                                           0))  # Rotate 30 deg around Y.
    slope_body.setMotionControl(agx.RigidBody.STATIC)
    material = agx.Material("slopeMaterial")
    slope_body.getGeometries()[0].setMaterial(material)
    return slope_body
Beispiel #5
0
        def add_slope():
            half_extents = agx.Vec3(length, 0.1, 0.005)
            slope = agxCollide.Geometry(agxCollide.Box(half_extents),
                                        agx.AffineMatrix4x4.translate(half_extents.x(), 0, -half_extents.z()))
            slope.setRotation(agx.EulerAngles(0, -self._slope_angle, 0))
            snakeapp.create_visual(slope, diffuse_color=agxRender.Color.Red())

            slope.setMaterial(self.material)
            self.add(slope)
            return slope
Beispiel #6
0
        def add_box():
            height = math.sin(self._slope_angle) * length
            half_extents = agx.Vec3(0.5, 0.1, height)
            box = agxCollide.Geometry(agxCollide.Box(half_extents),
                                      agx.AffineMatrix4x4.translate(0, 0, half_extents.z()))
            box.setParentFrame(self.slope.getParentFrame())
            box.setLocalPosition(0.5 + math.cos(self._slope_angle), 0, 0)
            snakeapp.create_visual(box, diffuse_color=agxRender.Color.Yellow())

            box.setMaterial(self.material)
            self.add(box)
    def __init__(self):
        super().__init__()

        servo_geometry = agxCollide.Geometry(servo_shape.deepCopy())
        servo_geometry.setEnableCollisions(False)
        snakeapp.create_visual(servo_geometry, agxRender.Color.Gray())

        bottom_geometry = agxCollide.Geometry(bottom_shape.deepCopy())
        bottom_geometry.setEnableCollisions(False)
        snakeapp.create_visual(bottom_geometry, agxRender.Color.Black())

        self.add(servo_geometry)
        self.add(bottom_geometry)
Beispiel #8
0
def build_scene():  # application entry point. Do not change method signature

    snake1 = Snake(num_modules=5, pitch_only=True)
    snake1.setLocalPosition(0, -0.1, 0)
    snakeapp.add(snake1)

    snake2 = Snake(num_modules=5, pitch_only=False)
    snake2.setLocalPosition(0, 0.1, 0)
    snakeapp.add(snake2)

    snake3 = Snake2(num_modules=5, pitch_only=False, with_camera=True)
    snake3.setLocalPosition(0, 0.4, 0)
    snakeapp.add(snake3)

    plane = agxCollide.Geometry(agxCollide.Box(2, 2, 0.1), agx.AffineMatrix4x4.translate(0, 0, -0.1 / 2))
    snakeapp.create_visual(plane, diffuse_color=agxRender.Color.Green())
    snakeapp.add(plane)
Beispiel #9
0
    def __init__(self, material: agx.Material = None):
        super().__init__()

        servo = agxCollide.Geometry(servo_shape.deepCopy())
        servo.setEnableCollisions(False)
        snakeapp.create_visual(servo, diffuse_color=agxRender.Color.Black())

        self.bottom = agx.RigidBody(
            agxCollide.Geometry(bottom_shape.deepCopy()))
        self.bottom.add(servo)
        snakeapp.create_visual(self.bottom, agxRender.Color.Orange())

        self.upper = agx.RigidBody(agxCollide.Geometry(upper_shape.deepCopy()))
        snakeapp.create_visual(self.upper, agxRender.Color.Orange())

        if material is not None:
            self.bottom.getGeometries()[0].setMaterial(material)
            self.upper.getGeometries()[0].setMaterial(material)

        self.hinge = create_constraint(pos=agx.Vec3(0.0, 0.0007, 0),
                                       axis=agx.agx.Vec3(0, 0, -1),
                                       rb1=self.bottom,
                                       rb2=self.upper,
                                       c=agx.Hinge)  # type: agx.Hinge

        self.hinge.setCompliance(1E-12)
        self.hinge.getMotor1D().setCompliance(1E-10)
        self.hinge.getMotor1D().setEnable(True)
        self.hinge.getLock1D().setEnable(False)
        self.hinge.getRange1D().setRange(-math.pi / 2, math.pi / 2)

        self.add(self.bottom)
        self.add(self.hinge)
        self.add(self.upper)
Beispiel #10
0
def build_scene():  # application entry point. Do not change method signature

    snakeapp.register_additional_scenes('build_scene_2')

    snake = Snake(NUM_SNAKE_MODULES, pitch_only=False)#, with_camera=True)  # type: snake_module.Snake
    snake.setPosition(agx.Vec3(0, 0, 0.1))
    snakeapp.add(snake)

    plane = agxCollide.Geometry(agxCollide.Box(2, 2, 0.1), agx.AffineMatrix4x4.translate(0, 0, -0.1/2))
    snakeapp.create_visual(plane, diffuse_color=agxRender.Color.Green())
    snakeapp.add(plane)

    ball = agxCollide.Geometry(agxCollide.Sphere(0.035), agx.AffineMatrix4x4.translate(0, 0, 0))
    snakeapp.create_visual(ball, diffuse_color=agxRender.Color.YellowGreen())
    ball.setPosition(agx.Vec3(-0.5, 0, 0.1))
    snakeapp.add(ball)

    snakeapp.add_event_listener(MyKeyEvent(ball))

    snakeapp.init_camera(eye=agx.Vec3(-1, -1, 0.5))

    snake_controller = SnakeBallControl(snake, ball)
    snake_controller.init_turning(math.pi / 9.0, math.pi * 2.0 / 3.0, 8.0, 0.0, math.pi * 0.0 / 180.0)
    snakeapp.add_event_listener(snake_controller)
Beispiel #11
0
 def add_floor():
     h = 0.1
     floor = agxCollide.Geometry(agxCollide.Box(2.5, 0.5, h), agx.AffineMatrix4x4.translate(0, 0, -h))
     snakeapp.create_visual(floor, diffuse_color=agxRender.Color.Green())
     self.add(floor)