Esempio n. 1
0
    def __init__(self, name, z_pos=0.3089):
        self._handle = sim.simGetObjectHandle(name)
        self.motorHandles = []
        self.motorHandles.append(
            sim.simGetObjectHandle('joint_front_left_wheel'))
        self.motorHandles.append(
            sim.simGetObjectHandle('joint_front_right_wheel'))
        self.motorHandles.append(
            sim.simGetObjectHandle('joint_back_left_wheel'))
        self.motorHandles.append(
            sim.simGetObjectHandle('joint_back_right_wheel'))

        self.joint_force = 10

        sim.simSetJointForce(self.motorHandles[0], self.joint_force)
        sim.simSetJointForce(self.motorHandles[1], self.joint_force)
        sim.simSetJointForce(self.motorHandles[2], self.joint_force)
        sim.simSetJointForce(self.motorHandles[3], self.joint_force)

        # self.robot_collection_handle = lib.simCreateCollection(b'nikbot',b'1')
        # lib.simAddObjectToCollection(self.robot_collection_handle,self._handle,b'1',b'00')
        # self.robot_collection_handle = sim.simGetCollectionHandle('nikbot')

        self.z_pos = z_pos
        self.wheel_distance = 0.38578
        self.wheel_radius = 0.23485
Esempio n. 2
0
    def exists(name: str) -> bool:
        """Checks if the given object is in the scene.

        :param id: name/id of object. If the name is appended by a "@alt"
            suffix, then the object handle based on the object's alternative
            name will be retrieved.
        :return: True of the object exists.
        """
        try:
            sim.simGetObjectHandle(name)
        except:
            return False
        return True
Esempio n. 3
0
 def _create_object(self, name):
     """Creates pyrep object for the correct type"""
     # TODO implement other types
     handle = sim.simGetObjectHandle(name)
     o_type = sim.simGetObjectType(handle)
     if ObjectType(o_type) == ObjectType.JOINT:
         return Joint(handle)
     elif ObjectType(o_type) == ObjectType.SHAPE:
         return Shape(handle)
     else:
         return None
Esempio n. 4
0
 def __init__(self, name_or_handle: Union[str, int]):
     if isinstance(name_or_handle, int):
         self._handle = name_or_handle
     else:
         self._handle = sim.simGetObjectHandle(name_or_handle)
     assert_type = self._get_requested_type()
     actual = ObjectType(sim.simGetObjectType(self._handle))
     if actual != assert_type:
         raise WrongObjectTypeError(
             'You requested object of type %s, but the actual type was '
             '%s' % (assert_type.name, actual.name))
    def __init__(self, scene: str = "room.ttt", dt: float = 0.05):
        """A class constructor.

        Args:
            dt: Delta time of simulation.
        """
        super(NavigationEnv, self).__init__(scene=scene, dt=dt, headless_mode=False)

        self._goal_threshold = 0.05
        self._collision_dist = 0.05

        self._robot = SmartBot(enable_vision=self.enable_vision)
        self._obstacles = sim.simGetObjectHandle("Obstacles_visual")
        self._navigation = self.navigation_type(self._robot, dt)

        self._goal = Dummy.create(size=0.1)
        self._goal.set_renderable(True)
        self._goal.set_name("Goal")

        max_linear_vel = (
            self._robot.wheel_radius * 2 * self._robot.velocity_limit[1] / 2
        )
        max_angular_vel = (
            self._robot.wheel_radius
            / self._robot.wheel_distance
            * np.diff(self._robot.velocity_limit)
        )[0]

        self.action_space = spaces.Box(
            *self._robot.velocity_limit,
            shape=self._robot.velocity_limit.shape,
            dtype="float32"
        )

        low = self._get_lower_observation(max_angular_vel)
        high = self._get_upper_observation(max_linear_vel, max_angular_vel)

        if self.enable_vision:
            self.observation_space = spaces.Dict(
                dict(
                    image=spaces.Box(
                        low=0, high=255, shape=self._robot.image.shape, dtype=np.uint8
                    ),
                    scalars=spaces.Box(low=low, high=high, dtype=np.float32),
                )
            )
        else:
            self.observation_space = spaces.Box(low=low, high=high, dtype=np.float32)
Esempio n. 6
0
    def get_object_type(name: str) -> ObjectType:
        """Gets the type of the object.

        :return: Type of the object.
        """
        return ObjectType(sim.simGetObjectType(sim.simGetObjectHandle(name)))