Skip to content
Snippets Groups Projects
Select Git revision
  • 591889c8e54649519e4b2e03000173e719dd504e
  • main default protected
2 results

visualiser.py

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    visualiser.py 1.61 KiB
    #!/usr/bin/env python
    
    import rospy
    
    from monitoring.watchdog import Watchdog
    from visualising.arduino import Arduino
    from visualising.connection import Connection, ArduinoException
    from visualising.animation import Animation
    
    
    class Visualiser:
        def __init__(self):
            port = rospy.get_param("/arduino_port", "/dev/ttyUSB0")
            baud = rospy.get_param("/arduino_baud", 57600)
            self.visualisation_strategy = rospy.get_param("/visualisation_strategy", 1)
    
            self.arduino = Arduino(Connection(port, baud))
            self.watchdog = Watchdog()
    
        def visualise(self):
            if self.visualisation_strategy == 1:
                self.mood_mode()
            elif self.visualisation_strategy == 2:
                self.info_mode()
            else:
                rospy.logwarn("Visualiser: The specified strategy is not recognised by the visualiser!")
    
        # TODO: Add all basic emotions!
        def mood_mode(self):
            happy = Animation(Animation.read_frames_from_file("animation_happy.txt"), 100, 1)
            ok = Animation(Animation.read_frames_from_file("animation_ok.txt"), 100, 1)
            sad = Animation(Animation.read_frames_from_file("animation_sad.txt"), 100, 1)
    
            while not rospy.is_shutdown():
                if self.watchdog.aggregated_domains > 0.7:
                    self.stream_animation(sad)
                else:
                    if self.watchdog.aggregated_domains > 0.4:
                        self.stream_animation(ok)
                    else:
                        self.stream_animation(happy)
    
        def info_mode(self):
            print("Hallo!")
    
        def stream_animation(self, animation):
            self.arduino.stream_animation(animation)