70 views
--- tags: Drane, Robotique, YWC --- # Programmer le robot Smart Cutebot en python ![](https://ppc-formation.fr/ap/ywc/resources/res_10002.jpg =350x) <iframe width="560" height="315" src="https://www.youtube.com/embed/WR4qvcAsto4?si=EYMFsJXzwGs5hXLI" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe> ## Fonctionnalités :::spoiler Ce robot intègre: (cliquer pour consulter) ![](https://nuage03.apps.education.fr/index.php/apps/files_sharing/publicpreview/jnKxANGgiYJnrzx?file=/&fileId=164129714&x=3674&y=2080&a=true&etag=6569d2f115ba4) - 2 x suiveurs de lignes - 1 x connecteur pour détecteur à ultrasons HC-SR04 (2 cm à 400 cm, précision ± 1,5 mm) permettant d'éviter les obstacles - 1 x buzzer - 2 x LEDs RGB frontales pouvant être utilisées comme indicateurs, feux de recul, etc. - 2 x LEDs RGB compatibles NeoPixel pour la création d'effets lumineux - 2 x interfaces pour servomoteurs ou modules complémentaires - 1 x interface I2C pour modules ou capteurs compatibles - 1 x récepteur IR pour un contrôle via une télécommande IR (non incluse) ::: ## Interfaces de programmation ### Programmation par blocs : avec Makecode Se rendre sur https://makecode.microbit.org Ajouter les blocs correspondants au robot en ajoutant l'extension Cutebot ![](https://nuage03.apps.education.fr/index.php/apps/files_sharing/publicpreview/kNjjE7xeEXoZNGY?file=/&fileId=163878183&x=4096&y=2304&a=true&etag=6568a1bc185fc) Blocs disponibles ![](https://nuage03.apps.education.fr/index.php/apps/files_sharing/publicpreview/Yzo33ZWmWamkXa8?file=/&fileId=163881371&x=4096&y=2304&a=true&etag=6568a44a68988 =x400) ### Programmation par blocs : avec Vittascience Se rendre sur le site de Vittascience : https://fr.vittascience.com/ Les blocs correspondants au robot sont disponibles sous l'onglet Robots ![](https://nuage03.apps.education.fr/index.php/apps/files_sharing/publicpreview/BEXaJJL9GkxRAfZ?file=/&fileId=164545348&x=3674&y=2080&a=true&etag=656b3a85cac1b) L'affichage mixte blocs/python permet de lire le code python associé à un programme en blocs. ## Programmation python : avec l'éditeur en ligne Télécharger la bibliothèque "BBC micro:bit Cutebot MicroPython" : https://github.com/Krakenus/microbit-cutebot-micropython/blob/master/cutebot.py Sur [python.microbit.org](https://python.microbit.org/v/3), cliquer sur ouvrir, puis charger le fichier en sélectionnant "Ajouter le fichier" au lieu de "remplacer le fichier". Des exemples de programmes sont disponibles [en ligne](https://github.com/Krakenus/microbit-cutebot-micropython/tree/master/examples) en lien avec le livret fourni avec le robot. Fonctions d'interface disponibles : ```python= def set_motors_speed(left_speed: int, right_speed: int) -> None: """ Sets speeds for both motors. """ def go_forward() -> None: """ Sets both motor to run forward with full speed """ def go_backward() -> None: """ Sets both motor to run backward with full speed """ def turn_left() -> None: """ Sets the motors to run with full speed but with opposite direction. The Cutebot will turn in place anticlockwise. """ def turn_right() -> None: """ Sets the motors to run with full speed but with opposite direction. The Cutebot will turn in place clockwise. """ def stop() -> None: """ Sets speed of both motors to 0. The Cutebot will stop immediately. """ def get_sonar_distance(unit: int = SONAR_CM, timeout_us: int = 30000) -> float: """ Returns object distance from sonar module in given unit. If negative number is returned, the timeout was reached during waiting for echo. """ def set_left_rgb_led(r: int = 0, g: int = 0, b: int = 0) -> None: """ Sets color of the left RGB led """ def set_right_rgb_led(r: int = 0, g: int = 0, b: int = 0) -> None: """ Sets color of the right RGB led """ def has_left_track() -> bool: """ Returns True whenever left tracker is on the black track. Otherwise returns False. """ def has_right_track() -> bool: """ Returns True whenever right tracker is on the black track. Otherwise returns False. """ def set_servo_1_angle(angle: int) -> None: """ Sets angle of S1 servo. """ def set_servo_2_angle(angle: int) -> None: """ Sets angle of S2 servo. """ ```