Ejemplo n.º 1
0
 def blink(self, color, iterations, period):
     with self.error_animation_lock:
         command = LedUserRequest()
         command.animation_mode.animation = LedRingAnimation.FLASHING
         command.colors = [color]
         command.iterations = iterations
         command.period = period
         self.start_led_ring_thread(command)
         try:
             if self.led_ring_animation_thread.is_alive():
                 self.led_ring_animation_thread.join()
         except RuntimeError:
             pass
Ejemplo n.º 2
0
    def shutdown(self):
        if not self.__is_shutdown:
            self.robot_status_subscriber.unregister()
            self.stop_led_ring_thread()
            self.user_animation_lock.acquire()

            command = LedUserRequest()
            command.colors = [WHITE]
            command.iterations = 1
            command.period = 2
            self.breath_animation(command)
            self.blink(WHITE, 8, 0.5)
            self.error_animation_lock.acquire()
            self.none_animation(None)
            self.__is_shutdown = True
Ejemplo n.º 3
0
    def solid(self, color, wait=False):
        """
        Sets the whole Led Ring to a fixed color.

        Example: ::

            from std_msgs.msg import ColorRGBA

            led_ring.solid([15, 50, 255])
            led_ring.solid(ColorRGBA(r=15, g=50, b=255), True)

        :param color: Led color in a list of size 3[R, G, B] or in an ColorRGBA object. RGB channels from 0 to 255.
        :type color: list[float]  or ColorRGBA
        :param wait: The service wait for the animation to finish or not to answer.
                For this method, the action is quickly done, so waiting doesn't take a lot of time.
        :type wait: bool
        :return: status, message
        :rtype: (int, str)
        """
        self.__check_ned_2_version()
        color_rgba = [
            color if isinstance(color, ColorRGBA) else ColorRGBA(*(color[:3] +
                                                                   [0]))
        ]
        user_led_request = LedUserRequest(animation_mode=LedRingAnimation(
            LedRingAnimation.SOLID),
                                          colors=color_rgba,
                                          wait_end=wait)
        result = self.__call_service(
            '/niryo_robot_led_ring/set_user_animation', LedUser,
            user_led_request)
        return self.__classic_return_w_check(result)
Ejemplo n.º 4
0
    def custom(self, led_colors):
        """
        Sends a colour command to all LEDs of the LED ring.
        The function expects a list of colours for the 30 LEDs  of the robot.

        Example: ::

            led_list = [[i / 30. * 255 , 0, 255 - i / 30.] for i in range(30)]
            led_ring.custom(led_list)

        :param led_colors: List of size 30 of led color in a list of size 3[R, G, B] or in an ColorRGBA object.
                RGB channels from 0 to 255.
        :type led_colors: list[list[float] or ColorRGBA]
        :return: status, message
        :rtype: (int, str)
        """
        self.__check_ned_2_version()
        color_rgba_list = [
            c if isinstance(c, ColorRGBA) else ColorRGBA(*(c[:3] + [0]))
            for c in led_colors
        ]
        user_led_request = LedUserRequest(animation_mode=LedRingAnimation(
            LedRingAnimation.CUSTOM),
                                          wait_end=True,
                                          colors=color_rgba_list)
        result = self.__call_service(
            '/niryo_robot_led_ring/set_user_animation', LedUser,
            user_led_request)
        return self.__classic_return_w_check(result)
Ejemplo n.º 5
0
    def rainbow_chase(self, period=0, iterations=0, wait=False):
        """
        Rainbow chase animation, like the led_ring_chase method.

        Examples: ::

            led_ring.rainbow_chase()
            led_ring.rainbow_chase(5, 2, True)
            led_ring.rainbow_chase(wait=True)

        :param period: Execution time for a pattern in seconds. If 0, the default time will be used.
        :type period: float
        :param iterations: Number of consecutive rainbow cycles. If 0, the animation continues endlessly.
        :type iterations: int
        :param wait: The service wait for the animation to finish or not to answer. If iterations
                is 0, the service answers immediately.
        :type wait: bool
        :return: status, message
        :rtype: (int, str)
        """
        self.__check_ned_2_version()
        user_led_request = LedUserRequest(animation_mode=LedRingAnimation(
            LedRingAnimation.RAINBOW_CHASE),
                                          wait_end=wait,
                                          period=period,
                                          iterations=iterations)
        result = self.__call_service(
            '/niryo_robot_led_ring/set_user_animation', LedUser,
            user_led_request)
        return self.__classic_return_w_check(result)
Ejemplo n.º 6
0
    def wipe(self, color, period=0, wait=False):
        """
        Wipes a color across the LED Ring, light a LED at a time.

        Examples: ::

            from std_msgs.msg import ColorRGBA

            led_ring.wipe(ColorRGBA(r=15, g=50, b=255))
            led_ring.wipe([15, 50, 255], 1, True)
            led_ring.wipe(ColorRGBA(r=15, g=50, b=255), wait=True)

        :param color: Led color in a list of size 3[R, G, B] or in an ColorRGBA object. RGB channels from 0 to 255.
        :type color: list[float]  or ColorRGBA
        :param period: Execution time for a pattern in seconds. If 0, the default time will be used.
        :type period: float
        :param wait: The service wait for the animation to finish or not to answer.
        :type wait: bool
        :return: status, message
        :rtype: (int, str)
        """
        self.__check_ned_2_version()
        color_rgba = [
            color if isinstance(color, ColorRGBA) else ColorRGBA(*(color[:3] +
                                                                   [0]))
        ]
        user_led_request = LedUserRequest(animation_mode=LedRingAnimation(
            LedRingAnimation.COLOR_WIPE),
                                          wait_end=wait,
                                          colors=color_rgba,
                                          period=period)
        result = self.__call_service(
            '/niryo_robot_led_ring/set_user_animation', LedUser,
            user_led_request)
        return self.__classic_return_w_check(result)
Ejemplo n.º 7
0
    def get_robot_status_led_ring_cmd(self):
        if self.robot_out_of_bounds:
            animation, colors = ROBOT_STATUS_TO_ANIM["out_of_bound"]
        elif self.rpi_overheating:
            animation, colors = ROBOT_STATUS_TO_ANIM["overheating"]
        elif self.robot_status in ROBOT_STATUS_TO_ANIM:
            animation, colors = ROBOT_STATUS_TO_ANIM[self.robot_status]
        else:
            # If no method defined (no entry for this key in dictionnay), turn off led rings
            rospy.logdebug(
                'Led ring - No Led control method defined for {} status and {} log'.format(self.robot_status,
                                                                                           self.robot_status_str))
            animation, colors = ROBOT_STATUS_TO_ANIM[RobotStatus.UNKNOWN]

        command = LedUserRequest()
        command.animation_mode.animation = animation
        command.colors = colors if isinstance(colors, list) else [colors]
        return command
Ejemplo n.º 8
0
    def alternate(self, color_list, period=0, iterations=0, wait=False):
        """
        Several colors are alternated one after the other.

        Examples: ::

            from std_msgs.msg import ColorRGBA

            color_list = [
                ColorRGBA(r=15, g=50, b=255),
                [255, 0, 0],
                [0, 255, 0],
            ]

            led_ring.alternate(color_list)
            led_ring.alternate(color_list, 1, 100, True)
            led_ring.alternate(color_list, iterations=20, wait=True)

        :param color_list: Led color list of lists of size 3[R, G, B] or ColorRGBA objects. RGB channels from 0 to 255.
        :type color_list: list[list[float] or ColorRGBA]
        :param period: Execution time for a pattern in seconds. If 0, the default time will be used.
        :type period: float
        :param iterations: Number of consecutive alternations. If 0, the Led Ring alternates endlessly.
        :type iterations: int
        :param wait: The service wait for the animation to finish all iterations or not to answer. If iterations
                is 0, the service answers immediately.
        :type wait: bool
        :return: status, message
        :rtype: (int, str)
        """
        self.__check_ned_2_version()
        color_rgba_list = [
            c if isinstance(c, ColorRGBA) else ColorRGBA(*(c[:3] + [0]))
            for c in color_list
        ]
        user_led_request = LedUserRequest(animation_mode=LedRingAnimation(
            LedRingAnimation.ALTERNATE),
                                          wait_end=wait,
                                          colors=color_rgba_list,
                                          period=period,
                                          iterations=iterations)
        user_led_request.animation_mode.animation = LedRingAnimation.ALTERNATE
        result = self.__call_service(
            '/niryo_robot_led_ring/set_user_animation', LedUser,
            user_led_request)
        return self.__classic_return_w_check(result)
Ejemplo n.º 9
0
    def flashing(self, color, period=0, iterations=0, wait=False):
        """
        Flashes a color according to a frequency. The frequency is equal to 1 / period.

        Examples: ::

            from std_msgs.msg import ColorRGBA

            led_ring.flashing([15, 50, 255])
            led_ring.flashing([15, 50, 255], 1, 100, True)
            led_ring.flashing([15, 50, 255], iterations=20, wait=True)

            frequency = 20  # Hz
            total_duration = 10 # seconds
            led_ring.flashing(ColorRGBA(r=15, g=50, b=255), 1./frequency, total_duration * frequency , True)

        :param color: Led color in a list of size 3[R, G, B] or in an ColorRGBA object. RGB channels from 0 to 255.
        :type color: list[float]  or ColorRGBA
        :param period: Execution time for a pattern in seconds. If 0, the default time will be used.
        :type period: float
        :param iterations: Number of consecutive flashes. If 0, the Led Ring flashes endlessly.
        :type iterations: int
        :param wait: The service wait for the animation to finish all iterations or not to answer. If iterations
                is 0, the service answers immediately.
        :type wait: bool
        :return: status, message
        :rtype: (int, str)
        """
        self.__check_ned_2_version()
        color_rgba = [
            color if isinstance(color, ColorRGBA) else ColorRGBA(*(color[:3] +
                                                                   [0]))
        ]
        user_led_request = LedUserRequest(animation_mode=LedRingAnimation(
            LedRingAnimation.FLASHING),
                                          wait_end=wait,
                                          colors=color_rgba,
                                          period=period,
                                          iterations=iterations)
        result = self.__call_service(
            '/niryo_robot_led_ring/set_user_animation', LedUser,
            user_led_request)
        return self.__classic_return_w_check(result)
Ejemplo n.º 10
0
    def go_up_down(self, color, period=0, iterations=0, wait=False):
        """
        LEDs turn on like a loading circle, and are turned off the same way.

        Examples: ::

            from std_msgs.msg import ColorRGBA

            led_ring.go_up_down(ColorRGBA(r=15, g=50, b=255))
            led_ring.go_up_down([15, 50, 255], 1, 100, True)
            led_ring.go_up_down(ColorRGBA(r=15, g=50, b=255), iterations=20, wait=True)


        :param color: Led color in a list of size 3[R, G, B] or in an ColorRGBA object. RGB channels from 0 to 255.
        :type color: list[float] or ColorRGBA
        :param period: Execution time for a pattern in seconds. If 0, the default time will be used.
        :type period: float
        :param iterations: Number of consecutive turns around the Led Ring. If 0, the animation
            continues endlessly.
        :type iterations: int
        :param wait: The service wait for the animation to finish or not to answer. If iterations
                is 0, the service answers immediately.
        :type wait: bool
        :return: status, message
        :rtype: (int, str)
        """
        self.__check_ned_2_version()
        color_rgba = [
            color if isinstance(color, ColorRGBA) else ColorRGBA(*(color[:3] +
                                                                   [0]))
        ]
        user_led_request = LedUserRequest(animation_mode=LedRingAnimation(
            LedRingAnimation.GO_UP_AND_DOWN),
                                          wait_end=wait,
                                          colors=color_rgba,
                                          period=period,
                                          iterations=iterations)
        result = self.__call_service(
            '/niryo_robot_led_ring/set_user_animation', LedUser,
            user_led_request)
        return self.__classic_return_w_check(result)
Ejemplo n.º 11
0
    def chase(self, color, period=0, iterations=0, wait=False):
        """
        Movie theater light style chaser animation.

        Examples: ::

            from std_msgs.msg import ColorRGBA

            led_ring.chase(ColorRGBA(r=15, g=50, b=255))
            led_ring.chase([15, 50, 255], 1, 100, True)
            led_ring.chase(ColorRGBA(r=15, g=50, b=255), iterations=20, wait=True)

        :param color: Led color in a list of size 3[R, G, B] or in an ColorRGBA object. RGB channels from 0 to 255.
        :type color: list or ColorRGBA
        :param period: Execution time for a pattern in seconds. If 0, the default time will be used.
        :type period: float
        :param iterations: Number of consecutive chase. If 0, the animation continues endlessly.
            One chase just lights one Led every 3 Leds.
        :type iterations: int
        :param wait: The service wait for the animation to finish all iterations or not to answer. If iterations
                is 0, the service answers immediately.
        :type wait: bool
        :return: status, message
        :rtype: (int, str)
        """
        self.__check_ned_2_version()
        color_rgba = [
            color if isinstance(color, ColorRGBA) else ColorRGBA(*(color[:3] +
                                                                   [0]))
        ]
        user_led_request = LedUserRequest(animation_mode=LedRingAnimation(
            LedRingAnimation.CHASE),
                                          wait_end=wait,
                                          colors=color_rgba,
                                          period=period,
                                          iterations=iterations)
        result = self.__call_service(
            '/niryo_robot_led_ring/set_user_animation', LedUser,
            user_led_request)
        return self.__classic_return_w_check(result)
Ejemplo n.º 12
0
    def turn_off(self, wait=False):
        """
        Turns off all Leds

        Example: ::

            led_ring.turn_off()

        :param wait: The service wait for the animation to finish or not to answer.
                For this method, the action is quickly done, so waiting doesn't take a lot of time.
        :type wait: bool
        :return: status, message
        :rtype: (int, str)
        """
        self.__check_ned_2_version()
        user_led_request = LedUserRequest(animation_mode=LedRingAnimation(
            LedRingAnimation.NONE),
                                          wait_end=wait)
        result = self.__call_service(
            '/niryo_robot_led_ring/set_user_animation', LedUser,
            user_led_request)
        return self.__classic_return_w_check(result)