def _initialize(self, **kwargs): """ Initialize method to generate the hinge. Inheriting from "box" makes sure there is a box of the given size in `self.link`. """ super(PassiveHinge, self)._initialize(**kwargs) # Create the variable size block. `create_link` is the recommended # way of doing this, because it sets some non-default link properties # (such as self_collide) which you generally need. length = kwargs["length"] self.var_block = self.create_component(BoxGeom(length, self.y, self.z, 0.1), "var-block") # We move the block in the x-direction so that it # just about overlaps with the other block (to # make it seem like a somewhat realistic joint) self.var_block.translate(Vector3(0.5 * (length + self.x) - self.JOINT_OFFSET, 0, 0)) # Now create a revolute joint at this same position. The # joint axis is in the y-direction. axis = Vector3(0, 1, 0) passive_joint = Joint("revolute", self.component, self.var_block, axis=axis) # Set some movement limits on the joint passive_joint.axis.limit = Limit(lower=math.radians(-45), upper=math.radians(45), effort=1.0) # Set the joint position - in the child frame! passive_joint.set_position(Vector3(-0.5 * length + self.JOINT_OFFSET, 0, 0)) # Don't forget to add the joint and the link self.add_joint(passive_joint) # Apply the generated color self.apply_color()
def _initialize(self, **kwargs): """ :param kwargs: :return: """ # Call super to initialize the cylinder part of the wheel super(Wheel, self)._initialize(**kwargs) # Create the small box that serves as the motor box_size = self.MOTOR_SIZE self.attachment = self.create_component( BoxGeom(box_size, box_size, box_size, 0.01), "cylinder-attach") # Get attachment position and axis of the motor joint anchor = Vector3(0, 0, 0.5 * self.LENGTH) axis = Vector3(0, 0, 1) # Size and position the box self.attachment.set_position(anchor + Vector3(0, 0, 0.5 * box_size)) # Create revolute joint. Remember: joint position is in child frame motor_joint = Joint("revolute", self.component, self.attachment, axis=axis) motor_joint.set_position(Vector3(0, 0, -0.5 * box_size)) # Set a force limit on the joint motor_joint.axis.limit = Limit(effort=0.01) self.add_joint(motor_joint) # Register a joint motor with a maximum velocity of # 50 rounds per minute (the speed is in radians per second) # We also give it a simple PID controller pid = PID(proportional_gain=1.0, integral_gain=0.1) max_speed = 2 * math.pi * 50.0 / 60 self.motors.append( VelocityMotor(self.id, "rotate", motor_joint, pid=pid, min_velocity=-max_speed, max_velocity=max_speed)) self.apply_color()
def _initialize(self, **kwargs): """ Initialize method to generate the hinge. Inheriting from "box" makes sure there is a box of the given size in `self.link`. """ super(PassiveHinge, self)._initialize(**kwargs) # Create the variable size block. `create_link` is the recommended # way of doing this, because it sets some non-default link properties # (such as self_collide) which you generally need. length = kwargs["length"] self.var_block = self.create_component( BoxGeom(length, self.y, self.z, 0.1), "var-block") # We move the block in the x-direction so that it # just about overlaps with the other block (to # make it seem like a somewhat realistic joint) self.var_block.translate( Vector3(0.5 * (length + self.x) - self.JOINT_OFFSET, 0, 0)) # Now create a revolute joint at this same position. The # joint axis is in the y-direction. axis = Vector3(0, 1, 0) passive_joint = Joint("revolute", self.component, self.var_block, axis=axis) # Set some movement limits on the joint passive_joint.axis.limit = Limit(lower=math.radians(-45), upper=math.radians(45), effort=1.0) # Set the joint position - in the child frame! passive_joint.set_position( Vector3(-0.5 * length + self.JOINT_OFFSET, 0, 0)) # Don't forget to add the joint and the link self.add_joint(passive_joint) # Apply the generated color self.apply_color()
def _initialize(self, **kwargs): """ :param kwargs: :return: """ # Call super to initialize the cylinder part of the wheel super(Wheel, self)._initialize(**kwargs) # Create the small box that serves as the motor box_size = self.MOTOR_SIZE self.attachment = self.create_component( BoxGeom(box_size, box_size, box_size, 0.01), "cylinder-attach") # Get attachment position and axis of the motor joint anchor = Vector3(0, 0, 0.5 * self.LENGTH) axis = Vector3(0, 0, 1) # Size and position the box self.attachment.set_position(anchor + Vector3(0, 0, 0.5 * box_size)) # Create revolute joint. Remember: joint position is in child frame motor_joint = Joint("revolute", self.component, self.attachment, axis=axis) motor_joint.set_position(Vector3(0, 0, -0.5 * box_size)) # Set a force limit on the joint motor_joint.axis.limit = Limit(effort=0.01) self.add_joint(motor_joint) # Register a joint motor with a maximum velocity of # 50 rounds per minute (the speed is in radians per second) # We also give it a simple PID controller pid = PID(proportional_gain=1.0, integral_gain=0.1) max_speed = 2 * math.pi * 50.0 / 60 self.motors.append(VelocityMotor(self.id, "rotate", motor_joint, pid=pid, min_velocity=-max_speed, max_velocity=max_speed)) self.apply_color()