예제 #1
0
    def __init__(self, num_modules: int, pitch_only=False):
        super().__init__()

        self.material = agx.Material("snake_material_{}".format(
            self.getUuid().__str__))

        self.modules = []

        for i in range(0, num_modules):
            module = SnakeModule(self.material)
            module.setPosition(module_len * i, 0, 0)
            module.setRotation(agx.EulerAngles(math.pi / 2, 0, 0))

            if not pitch_only:
                if i % 2 != 0:
                    module.setRotation(agx.EulerAngles(0, 0, 0))

            if i > 0:
                merged_body = agx.MergedBody()
                merged_body.add(
                    agx.MergedBodyEmptyEdgeInteraction(
                        self.modules[i - 1].upper, module.bottom))
                snakeapp.add(merged_body)

            self.modules.append(module)
            self.add(module)
예제 #2
0
def build_scene():
    snakeapp.register_additional_scenes('build_scene2')

    angle = 0
    for y in [-1, 0, 1]:

        angle += 10
        obstacle = Obstacle(0.5, angle)
        obstacle.setLocalPosition(0, y, 0)
        snakeapp.add(obstacle)

        snake = Snake(5)
        snake.setLocalPosition(-0.5, y, 0.05)
        snake.setLocalRotation(agx.EulerAngles(math.pi / 2, 0, 0))
        snakeapp.add(snake)

        snake_obstacle_cm = snakeapp.sim().getMaterialManager() \
            .getOrCreateContactMaterial(snake.material, obstacle.material)  # type: agx.ContactMaterial

        snake_obstacle_cm.setFrictionCoefficient(2)  # a lower makes contacts more slippery

        snake_obstacle_cm.setUseContactAreaApproach(True)
        snake_obstacle_cm.setYoungsModulus(3E9)

        fm = agx.IterativeProjectedConeFriction(agx.FrictionModel.DIRECT)
        snake_obstacle_cm.setFrictionModel(fm)

        for i in range(0, snake.num_servos):
            sm = ExampleSineMotion(snake, i)
            if i % 2 == 0:
                sm.amplitude = math.radians(-90)
            else:
                sm.amplitude = math.radians(30)
            snakeapp.add_event_listener(sm)
    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)
예제 #4
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())
예제 #5
0
def build_scene():
    snakeapp.register_additional_scenes('build_scene2')

    slope = create_slope()
    snakeapp.add(slope)

    snake = Snake(5)
    snake.setPosition(0, 0, 0.1)
    snake.setRotation(agx.EulerAngles(0, -math.radians(slope_angle), 0.2))
    snakeapp.add(snake)
예제 #6
0
def build_scene2():
    slope = create_slope()
    snakeapp.add(slope)

    snake = Snake(5)
    snake.setPosition(0, 0, 0.1)
    snake.setRotation(agx.EulerAngles(0, -math.radians(slope_angle), 0.2))
    snakeapp.add(snake)

    snake_obstacle_cm = snakeapp.sim().getMaterialManager() \
        .getOrCreateContactMaterial(snake.material, slope.getGeometries()[0].getMaterial())  # type: agx.ContactMaterial

    snake_obstacle_cm.setFrictionCoefficient(10)
    snake_obstacle_cm.setYoungsModulus(3E4)
    def __init__(self, material: agx.Material = None):
        super().__init__()

        self.len = 0

        self.intermediate = IntermediatePart(material)
        self.intermediate.setPosition(agx.Vec3(-module_len / 2 - intermediate_len, 0, 0))

        self.bottom = BottomPart()

        self.add(self.intermediate)
        self.add(self.bottom)

        merged_body = self.intermediate.merged_body
        merged_body.add(agx.MergedBodyEmptyEdgeInteraction(self.intermediate.body, self.bottom))
        snakeapp.add(merged_body)
    def __init__(self, material: agx.Material = None):
        super().__init__()

        self.len = (module_len * 0.5) + intermediate_len

        self.upper = UpperPart()
        self.intermediate = IntermediatePart(material)
        self.intermediate.setRotation(agx.EulerAngles(math.pi, 0, math.pi))
        self.intermediate.setPosition(agx.Vec3(module_len / 2 + intermediate_len, 0, 0))

        self.add(self.upper)
        self.add(self.intermediate)

        merged_body = self.intermediate.merged_body
        merged_body.add(agx.MergedBodyEmptyEdgeInteraction(self.upper, self.intermediate.body))
        snakeapp.add(merged_body)
예제 #9
0
def build_scene():

    snakeapp.create_sky()

    snake = Snake(6)
    snake.setRotation(agx.EulerAngles(math.pi / 2, 0, 0))
    snake.setPosition(agx.Vec3(0, .5, 0.3))
    snakeapp.add(snake)

    terrain = Terrain()

    terrain_snake_cm = snakeapp.sim().getMaterialManager() \
        .getOrCreateContactMaterial(terrain.material, snake.material)  # type: agx.ContactMaterial
    terrain_snake_cm.setFrictionCoefficient(3)
    terrain_snake_cm.setUseContactAreaApproach(True)
    terrain_snake_cm.setYoungsModulus(3E3)

    fm = agx.IterativeProjectedConeFriction(agx.FrictionModel.DIRECT)
    terrain_snake_cm.setFrictionModel(fm)

    for i in range(0, snake.num_servos):
        snakeapp.add_event_listener(ExampleSineMotion(snake, i))

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

    import agxSDK

    class ReadSensor(agxSDK.StepEventListener):
        def __init__(self):
            super().__init__(agxSDK.StepEventListener.POST_STEP)

        def post(self, time):
            pass
            # for i in range(0, snake.num_sensors):
            #     print("Sensor{} force={}".format(i, snakeapp.get_sum_force_magnitude(snake.sensors[i])))
            # print("")

    snakeapp.add_event_listener(ReadSensor())
예제 #10
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)
예제 #11
0
    def __init__(self):

        hf = agxCollide.HeightField.createFromFile("assets/textures/dirtRoad128.png", 6, 6, -0.5, 0.5)
        terrain = agxModel.Terrain(hf)
        snakeapp.add(terrain)

        self.material = agx.Material("GroundMaterial")

        terrain_data = terrain.getDataInterface()  # type: agxModel.TerrainDataInterface
        terrain_data.setMaxCompressionMultiplier(32)
        particle_adhesion = 0
        deformity = 100
        angle_of_repose = math.pi * 0.2
        material_index = 0
        terrain_data.add(self.material, material_index, particle_adhesion, deformity, angle_of_repose)

        range_for_youngs_modulus = agx.RangeReal(10000, 20000)
        terrain_renderer = agxOSG.TerrainRenderer(terrain, range_for_youngs_modulus, snakeapp.root())
        snakeapp.add(terrain_renderer)

        terrain_visual = terrain_renderer.getTerrainNode()
        agxOSG.setDiffuseColor(terrain_visual, Color(0.7, 0.7, 0.8, 1))
        agxOSG.setSpecularColor(terrain_visual, Color(0.4, 0.4, 0.4, 1))
        agxOSG.setShininess(terrain_visual, 128)
예제 #12
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)