@@ -43,8 +43,7 @@ def __init__(self, robot):
4343
4444 self ._detect_faces = False
4545 self ._detect_custom_objects = False
46- # TODO implement
47- # self._detect_motion = False
46+ self ._detect_motion = False
4847 self ._display_camera_feed_on_face = False
4948
5049 robot .events .subscribe (self ._handle_mirror_mode_disabled_event , events .Events .mirror_mode_disabled )
@@ -62,7 +61,7 @@ def _handle_mirror_mode_disabled_event(self, _robot, _event_type, _msg):
6261 def _handle_vision_modes_auto_disabled_event (self , _robot , _event_type , _msg ):
6362 self ._detect_faces = False
6463 self ._detect_custom_objects = False
65- # self._detect_motion = False
64+ self ._detect_motion = False
6665 self ._display_camera_feed_on_face = False
6766
6867 @property
@@ -73,10 +72,9 @@ def detect_faces(self):
7372 def detect_custom_objects (self ):
7473 return self ._detect_custom_objects
7574
76- # TODO implement
77- # @property
78- # def detect_motion(self):
79- # return self._detect_motion
75+ @property
76+ def detect_motion (self ):
77+ return self ._detect_motion
8078
8179 @property
8280 def display_camera_feed_on_face (self ):
@@ -88,8 +86,8 @@ async def disable_all_vision_modes(self):
8886 await self .enable_face_detection (False , False )
8987 if self .detect_custom_objects :
9088 await self .enable_custom_object_detection (False )
91- # if self.detect_motion:
92- # await self.enable_motion_detection(False)
89+ if self .detect_motion :
90+ await self .enable_motion_detection (False )
9391 if self .display_camera_feed_on_face :
9492 await self .enable_display_camera_feed_on_face (False )
9593
@@ -142,23 +140,46 @@ async def enable_face_detection(
142140 enable_gaze_detection = False )
143141 return await self .grpc_interface .EnableFaceDetection (enable_face_detection_request )
144142
145- # TODO implement
146- # @connection.on_connection_thread()
147- # async def enable_motion_detection(self, detect_motion: bool = True):
148- # """Enable motion detection on the robot's camera
149- #
150- # :param detect_motion: Specify whether we want the robot to detect motion.
151- #
152- # .. testcode::
153- #
154- # import anki_vector
155- # with anki_vector.Robot() as robot:
156- # robot.vision.enable_motion_detection(detect_motion=True)
157- # """
158- # self._detect_motion = detect_motion
159-
160- # enable_motion_detection_request = protocol.EnableMotionDetectionRequest(enable=detect_motion)
161- # return await self.grpc_interface.EnableMotionDetection(enable_motion_detection_request)
143+ @connection .on_connection_thread ()
144+ async def enable_motion_detection (self , detect_motion : bool = True ):
145+ """Enable motion detection on the robot's camera
146+
147+ :param detect_motion: Specify whether we want the robot to detect motion.
148+
149+ .. testcode::
150+
151+ import time
152+
153+ import anki_vector
154+ from anki_vector.events import Events
155+ from anki_vector.util import degrees
156+
157+ def on_robot_observed_motion(robot, event_type, event):
158+ print(f"--------- Vector observed motion --------- \n {event}")
159+
160+ with anki_vector.Robot(show_viewer=True) as robot:
161+ robot.events.subscribe(on_robot_observed_motion, Events.robot_observed_motion)
162+
163+ # If necessary, move Vector's Head and Lift to make it easy to see his face
164+ robot.behavior.set_head_angle(degrees(45.0))
165+ robot.behavior.set_lift_height(0.0)
166+
167+ robot.vision.enable_motion_detection(detect_motion=True)
168+
169+ print("\n \n Vector is waiting to see motion. Make some movement within Vector's camera view.\n \n ")
170+
171+ try:
172+ while True:
173+ time.sleep(0.5)
174+ except KeyboardInterrupt:
175+ pass
176+
177+ robot.events.unsubscribe(on_robot_observed_motion, Events.robot_observed_motion)
178+ """
179+ self ._detect_motion = detect_motion
180+
181+ enable_motion_detection_request = protocol .EnableMotionDetectionRequest (enable = detect_motion )
182+ return await self .grpc_interface .EnableMotionDetection (enable_motion_detection_request )
162183
163184 @connection .on_connection_thread ()
164185 async def enable_display_camera_feed_on_face (self , display_camera_feed_on_face : bool = True ):
0 commit comments