Image

Introduction to GoPiGo

This project utilized the Dexter Industries GoPiGo base set, a Raspberry Pi 3B, Grove Sensors, and Servo motors - both standard and continuous. The main objective was to gain familiarity with the GoPiGo Raspberry Pi robotic platform through the completion of two challenges and the bonus challenge.

Image

Challenge 1:

To accomplish the challenge of blinking external LEDs and running the GoPiGo motors, we looked at example code stored on the IDE. We found two files (blink_led.py and motor.py) that contained the exact code we needed to accomplish these tasks. In order to make the hardware work properly with the code, we researched GPIO pin numbering. This allowed us to successfully connect the LEDs positive lead to GPIO 17 and its negative lead to ground. The code then instructs the GoPiGo sytem to "open its eyes", run the motors, "close its eyes", and blink the external LED five times. Refer to the code and video below.

#!/usr/bin/python3

import RPi.GPIO as GPIO
import time

def main():
    print('Test')

    # Initialize GoPiGo3 object
    gpg = Device('this')

    # Run motor and open eyes
    gpg.open_eyes()
    gpg.forward()
    sleep(2)

    # Stop motor and close eyes
    gpg.stop()
    gpg.close_eyes()
    print("Done")
    LED_BCM_PIN = 17
    #setup output
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(LED_BCM_PIN,GPIO.OUT)

    #Initialize to Off
    GPIO.output(LED_BCM_PIN,GPIO.LOW)

    for i in range(5):

        #Turn on LED
        GPIO.output(LED_BCM_PIN,GPIO.HIGH)
        print("LED on")
        sleep(.1)

        #Turn off LED
        GPIO.output(LED_BCM_PIN,GPIO.LOW)
        print("LED off")
        sleep(.1)

    # Clean up pins that were used in this program
    GPIO.cleanup()
    print("done")

if __name__ == '__main__':
    main()

Challenge 2:

This challenge tasked us with connecting Grove Sensors and Servo motors to the system. We decided to make a robot whose motors oscillate 180 degrees when a button is pressed, but stops when the button is not pressed. We were able to find example code for the use of the Grove Sensor pushbutton. It contained an if statement whose output was dependent on the pushbutton's state. We also found example code for running the Servo motors through the GoPiGo system. Our final Challenge 2 code combines these two examples by having the oscillation instructions for the Servo placed within the true condition of the if statement. Refer below for the code and video of the robot.

#!/usr/bin/python3
def main():
    # Initialize objects
    gpg = Device("this")
    button = gpg.init_button_sensor("AD2")
    angle_servo = gpg.init_servo("SERVO1")
    cont_servo = gpg.init_servo("SERVO2")
    angle = 0

    while True:
        if button.is_button_pressed():
            # Switch between extreme values
            if angle == 0:
                cont_servo.rotate_servo(0)
                angle = 180
            else:
                cont_servo.rotate_servo(180)
                angle = 0
            angle_servo.rotate_servo(angle)
            sleep(1)

        else:
            cont_servo.rotate_servo(90)
            angle_servo.rotate_servo(90)

    print("Done")

if __name__ == '__main__':
    main()

BonusChallenge:

This challenge involves interaction between the GoPiGo Raspberry Pi and LEGO MINDSTORM EV3 systems, conveniently an integral part of our term project. We started this challenge by achieving physical interaction. Specifically, this meant lighting an LED with the GoPiGo and reading the light intensity with the LEGO color sensor. When the light intensity is read as greater than 4, a large motor is driven by the EV3. Otherwise, the motor does not move. Therefore, the motion of the motor can be controlled by whether or not the sensor is held close to the LED. See code and video below.

#!/usr/bin/python3

def main():
    ev3 = Device('this')
    color_sensor=ev3.ColorSensor('in1')
    color_sensor.mode = 'COL-REFLECT'
    motor = ev3.LargeMotor('outA')
    while True:
        rcolor = color_sensor.reflected_light_intensity
        if rcolor>4:
            motor.run_forever(speed_sp=200)
        else:
            motor.stop(stop_action="hold")
if __name__ == '__main__':
    main()

Additionally, we were able to connect the devices virtually using the "Device" command. This required wireless communication between the two platforms. Our goal was to run code on the GoPiGo system that, based on the state of a pushbutton, instructs the EV3 to either move or stop a motor. This accomplishes the same task as the above without requiring any physical interaction between the devices. One issue with this method is that it adds a small amount of delay between the input and output, likely due to a slow network. See code and video below.

#!/usr/bin/python3

def main():
    gpg = Device("this")
    button = gpg.init_button_sensor("AD2")
    ev3 = Device('172.16.216.92')
    motor = ev3.LargeMotor('outA')
    while True:
        if button.is_button_pressed():
            motor.run_forever(speed_sp=200)
        else:
            motor.stop(stop_action="hold")

if __name__ == '__main__':
    main()