def _lazy_init(self):
        """
        Lazy-initialize effect
        """
        # ROS Services Setup
        rospy.wait_for_service(GazeboServiceName.GET_MODEL_PROPERTIES.value)
        rospy.wait_for_service(GazeboServiceName.GET_VISUAL_NAMES.value)
        rospy.wait_for_service(GazeboServiceName.GET_VISUALS.value)

        get_model_prop = ServiceProxyWrapper(
            GazeboServiceName.GET_MODEL_PROPERTIES.value, GetModelProperties)
        get_visual_names = ServiceProxyWrapper(
            GazeboServiceName.GET_VISUAL_NAMES.value, GetVisualNames)
        get_visuals = ServiceProxyWrapper(GazeboServiceName.GET_VISUALS.value,
                                          GetVisuals)

        # Get all model's link names
        body_names = get_model_prop(
            GetModelPropertiesRequest(model_name=self.model_name)).body_names
        link_names = ["%s::%s" % (self.model_name, b) for b in body_names]

        res = get_visual_names(GetVisualNamesRequest(link_names=link_names))
        get_visuals_req = GetVisualsRequest(link_names=res.link_names,
                                            visual_names=res.visual_names)
        self.orig_visuals = get_visuals(get_visuals_req)
Esempio n. 2
0
    def update_model_visual(self, racecar_name, body_shell_type, car_color):
        # Get all model's link names
        body_names = self.get_model_prop(GetModelPropertiesRequest(model_name=racecar_name)) \
            .body_names
        link_names = ["%s::%s" % (racecar_name, b) for b in body_names]
        res = self.get_visual_names(GetVisualNamesRequest(link_names=link_names))
        get_visuals_req = GetVisualsRequest(link_names=res.link_names,
                                            visual_names=res.visual_names)
        visuals = self.get_visuals(get_visuals_req)

        if const.F1 in body_shell_type.lower():
            self._hide_visuals(visuals=visuals)
        else:
            self._update_color(visuals=visuals,
                               car_color=car_color)
Esempio n. 3
0
    def get_model_visuals(self, model_name):
        """Get the model visuals associated to the model name

        Args:
            model_name (str): The model name for the race car we want to hide visuals for.
                              e.g. racecar_0

        Returns:
            Visuals: The visuals of the current model.
        """
        # Get all model's link names
        body_names = self._get_model_prop(GetModelPropertiesRequest(model_name=model_name)) \
            .body_names
        link_names = ["%s::%s" % (model_name, b) for b in body_names]
        res = self._get_visual_names(GetVisualNamesRequest(link_names=link_names))
        get_visuals_req = GetVisualsRequest(link_names=res.link_names,
                                            visual_names=res.visual_names)
        visuals = self._get_visuals(get_visuals_req)

        return visuals
Esempio n. 4
0
    def _are_visuals_hidden(self, link_names, visual_names):
        """Check if the visuals are hidden.
           If all the visuals are visible as False or all are transparent,
           return True.

        Args:
            link_names ([str]): A list of link names.
            visual_names ([str]): A list of visual names.

        Returns:
            bool: If the visuals are hiddens
        """
        get_visuals_req = GetVisualsRequest(link_names=link_names,
                                            visual_names=visual_names)
        visuals = self._get_visuals(get_visuals_req)
        # all transparency are 1.0
        all_transparent = (int(sum(visuals.transparencies)) == len(link_names))
        # all visible are false
        all_non_visible = (sum(visuals.visibles) == 0)
        return all_transparent or all_non_visible