def create_sphere(position: agx.Vec3): shape = agxCollide.Sphere(0.5) geometry = agxCollide.Geometry(shape) body = agx.RigidBody(geometry) body.setPosition(position) demoutils.create_visual(body) return body
def create_box(position: agx.Vec3): shape = agxCollide.Box(agx.Vec3(0.5, 0.5, 0.5)) geometry = agxCollide.Geometry(shape) body = agx.RigidBody(geometry) body.setPosition(position) demoutils.create_visual(body) return body
def create_cylinder(position: agx.Vec3): shape = agxCollide.Cylinder(0.5, 1) geometry = agxCollide.Geometry(shape) body = agx.RigidBody(geometry) body.setPosition(position) demoutils.create_visual(body) body.setRotation(agx.EulerAngles(agx.PI_2, 0, 0)) return body
def build_scene(): sim = demoutils.sim() # Create a geometry with a plane shape as our 'floor' floor_geometry = agxCollide.Geometry(agxCollide.Box(agx.Vec3(10, 10, 0.1))) demoutils.create_visual(floor_geometry, Color.Green()) sim.add(floor_geometry) # Add the geometry to the simulation sim.add(create_box(agx.Vec3(-2, 3, 5))) sim.add(create_sphere(agx.Vec3(0, 1, 5))) sim.add(create_capsule(agx.Vec3(3, 5, 5))) sim.add(create_cylinder(agx.Vec3(-3, -2, 5)))
def build_scene1(): # Create a geometry with a plane shape as our 'floor' floor_geometry = agxCollide.Geometry(agxCollide.Box(agx.Vec3(10, 10, 0.1))) demoutils.create_visual(floor_geometry) demoutils.sim().add(floor_geometry) # Add the geometry to the simulation rb1 = agx.RigidBody() # Create a rigid body rb1.add(agxCollide.Geometry(agxCollide.Sphere( 0.5))) # Add a geometry with a sphere-shape of radius 0.5 rb1.setPosition(0, 0, 5.0) # Position the sphere somewhere above our plane demoutils.create_visual(rb1) demoutils.sim().add( rb1) # Add the body to the simulation. The geometry will also be added
def build_scene2(): # Create a geometry with a plane shape as our 'floor' floor_geometry = agxCollide.Geometry(agxCollide.Box(agx.Vec3(10, 10, 0.1))) demoutils.create_visual(floor_geometry, diffuse_color=Color.Green()) demoutils.sim().add(floor_geometry) # Add the geometry to the simulation for x in range(-5, 5): for y in range(-5, 5): for z in range(1, 8): rb = agx.RigidBody() # Create a rigid body rb.add(agxCollide.Geometry(agxCollide.Sphere( 0.2))) # Add a geometry with a sphere-shape of radius 0.2 rb.setPosition( x + random(), y + random(), z) # Position the sphere somewhere above our plane demoutils.create_visual(rb) demoutils.sim().add( rb ) # Add the body to the simulation. The geometry will also be added
def __init__(self): super().__init__() len1 = 2 len2 = 1 self.link1 = create_link(len1) self.link2 = create_link(len2) self.link2.setPosition(len2, 0, len1) self.link2.setRotation(agx.EulerAngles(0, math.radians(-90), 0)) self.link1.getGeometries()[0].setEnableCollisions(self.link2.getGeometries()[0], False) demoutils.create_visual(self.link1) demoutils.create_visual(self.link2) self.hinge = demoutils.create_constraint( pos=agx.Vec3(width, 0, len1), axis=agx.Vec3(0, 1, 0), rb1=self.link1, rb2=self.link2, c=agx.Hinge) # type: agx.Hinge self.hinge.setCompliance(1e-8) self.hinge.getLock1D().setEnable(False) self.hinge.getMotor1D().setEnable(False) self.hinge.getRange1D().setEnable(True) self.hinge.getRange1D().setRange(math.radians(-45), math.radians(75)) f1 = agx.Frame() f1.setTranslate(agx.Vec3(width, 0, len1 - (len1 * 0.7))) f2 = agx.Frame() f2.setTranslate(agx.Vec3(-width, 0, 0)) self.distance = agx.DistanceJoint(self.link1, f1, self.link2, f2) self.distance.getMotor1D().setEnable(False) self.distance.getLock1D().setEnable(True) self.add(self.link1) self.add(self.link2) self.add(self.hinge) self.add(self.distance)
def __init__(self, keyboard): """ Args: keyboard: seaFloor: wing_scale: depth: """ super().__init__() self.keyboard = keyboard self.plot_pitch = [] self.plot_wing_angle = [] self.plot_depth = [] self.plot_roll = [] self.plotted = False print("initilaized master and vields") # building models rov_material = self.build_material('AluminumMaterial', ROV_BODY_DENSITY) wing_material = self.build_material('AluminumMaterial', ROV_WING_DENSITY) tank_material = self.build_material('AluminumMaterial', ROV_TANK_DENSITY) builder = rov_builder() print("rov builder ready") # rov body self.link1 = builder.create_rov_body(rov_material, name='rovBody', scale=ROV_SCALE, cm=(0.27511, -0.18095, 0.0494), tank_material=tank_material) print("buildt rov body") print("volumebounds: ", self.link1.getGeometry("Rov_body").getBoundingVolume().size()) # wing left self.link2 = builder.create_wing_right(wing_material, WING_SCALE, "wing_r", rot=(0, 0, 0)) link2rot = self.link2.getPosition() print("buildt right wing", link2rot) # wing right self.link3 = builder.create_wing_left(wing_material, WING_SCALE, "wing_l", rot=(0, 0, 0)) link3rot = self.link3.getPosition() print("buildt left wing") # disabling internal collisions self.link1.getGeometry('Rov_body').setEnableCollisions( self.link2.getGeometry('wing_r'), False) self.link1.getGeometry('Rov_body').setEnableCollisions( self.link3.getGeometry('wing_l'), False) print("removed internal collitions") # adding visualisation demoutils.create_visual(self.link1) demoutils.create_visual(self.link2) demoutils.create_visual(self.link3) print("created visuals") # conecting models # left wing self.hinge1 = self.build_hinge(link=self.link1, part=self.link2, pos=link2rot, axis=agx.Vec3(0, 1, 0), lock=False, motor=True, range=(MIN_WING_ANGLE, MAX_WING_ANGLE), compliance=1e-5) # right wing self.hinge2 = self.build_hinge(self.link1, self.link3, pos=link3rot, axis=agx.Vec3(0, 1, 0), lock=False, motor=True, range=(MIN_WING_ANGLE, MAX_WING_ANGLE), compliance=1e-5) # sonar print("buildt joints") # adding models to assembly self.add(self.link1) self.add(self.link2) self.add(self.link3) print("added models to assembly") self.add(self.hinge1) self.add(self.hinge2) print("aded links to assembly") self.left_wing_angle = lambda: self.hinge1.getAngle() self.right_wing_angle = lambda: self.hinge2.getAngle() print("set the wing controll functions") self.wing_step_length = deg2rad(2) print("added wing step lenght") self.setName('rov') print("set name") Sec.postCallback(self.post)
def create_and_add_ground(): ground = agxCollide.Geometry(agxCollide.Box(1, 1, 0.05)) demoutils.create_visual(ground, Color.Green()) demoutils.sim().add(ground) return ground