Hackster is hosting Hackster Holidays, Finale: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Tuesday!Stream Hackster Holidays, Finale on Tuesday!
MJRoBot (Marcelo Rovai)
Published © GPL3+

When COZMO the Robot Meets Raspberry Pi

COZMO is a great small robot that can be fully programmed using Python. Imagine what you can do, also integrating Cozmo with a Raspberry Pi!

IntermediateFull instructions provided8 hours8,444
When COZMO the Robot Meets Raspberry Pi

Things used in this project

Story

Read more

Schematics

eletrical diagram

Code

Code snippet #12

Plain text
''' Drive a Square '''import cozmo
from cozmo.util import degrees, distance_mm, speed_mmpsdef cozmo_program(robot: cozmo.robot.Robot):
    robot.say_text("Hello marcelo, let's drive a square").wait_for_completed()
    for _ in range (4):
        robot.drive_straight(distance_mm(150), speed_mmps(50)).wait_for_completed()
        robot.say_text("Left").wait_for_completed()
        robot.turn_in_place(degrees(90)).wait_for_completed()   
    robot.say_text("and finished!").wait_for_completed()cozmo.run_program(cozmo_program)

Code snippet #13

Plain text
from gpiozero import LEDfrom time import sleep
led = LED(13)
while True:
    led.on()
    sleep(1)
    led.off()
    sleep(1)

Code snippet #14

Plain text
import cozmo
from cozmo.util import degrees
from time import sleep
from gpiozero import LED
led = LED(13)

def cozmo_program(robot: cozmo.robot.Robot):
    robot.set_head_angle(degrees(30)).wait_for_completed()
    robot.say_text("Hello Raspbery pi").wait_for_completed()
    robot.set_lift_height(30.0).wait_for_completed()
    hello_rpi()
    robot.set_head_angle(degrees(0)).wait_for_completed()
    robot.set_lift_height(0.0).wait_for_completed()

def hello_rpi():
    for _ in range(3):
        led.on()
        sleep(1)
        led.off()
        sleep(1)
    
cozmo.run_program(cozmo_program)

Code snippet #15

Plain text
import cozmofrom cozmo.util import degreesfrom gpiozero import LED, Button
from signal import pause
led = LED(13)
button = Button(20)def cozmo_program(robot: cozmo.robot.Robot):
    button.wait_for_press()
    led.on()
    robot.set_head_angle(degrees(30)).wait_for_completed()
    robot.say_text("Hello Raspbery pi. Button pressed").wait_for_completed()
    robot.set_head_angle(degrees(0)).wait_for_completed()
    led.off()
cozmo.run_program(cozmo_program)

Code snippet #16

Plain text
from gpiozero import LED, Buttonfrom time import sleep
red = LED(13)
yellow = LED(19)
green = LED(26)
button = Button(20)def cozmo_program(robot: cozmo.robot.Robot):
    robot.say_text("Hello Raspbery pi. Press the button").wait_for_completed()
    button.wait_for_press()
    robot.drive_straight(distance_mm(150), speed_mmps(50)).wait_for_completed()
    robot.turn_in_place(degrees(90)).wait_for_completed()
    red.on()
    robot.set_all_backpack_lights(cozmo.lights.red_light)
    robot.say_text("red").wait_for_completed()
    
    button.wait_for_press()
    red.off()
    yellow.on()
    robot.set_center_backpack_lights(cozmo.lights.white_light)
    robot.say_text("yellow").wait_for_completed()
    sleep(1)
    
    button.wait_for_press()
    yellow.off()
    green.on()
    robot.set_all_backpack_lights(cozmo.lights.green_light)
    robot.say_text("green").wait_for_completed()
    sleep(1)
    
    button.wait_for_press()
    green.off()
    robot.set_all_backpack_lights(cozmo.lights.off_light)
    robot.say_text("bye, bye Raspbery pi").wait_for_completed()
    robot.turn_in_place(degrees(90)).wait_for_completed()
    robot.drive_straight(distance_mm(150), speed_mmps(50)).wait_for_completed()
    robot.turn_in_place(degrees(180)).wait_for_completed()
    
cozmo.run_program(cozmo_program)

Credits

MJRoBot (Marcelo Rovai)
67 projects • 959 followers
Professor, Engineer, MBA, Master in Data Science. Writes about Electronics with a focus on Physical Computing, IoT, ML, TinyML and Robotics.

Comments