Image

Country CrockBot by Alex, Khalil, Martin, Omar and Sahana

Description:

Our robot has one purpose -- to pass plates of butter. Upon activation, it moves forward until it senses that a plate or any other object is in range, and stops moving using a proportional control code. Then, the two prongs move down until the touch sensors are pushed, indicating that the prongs have latched onto the plate. The robot then moves backwards until it senses that it has returned to the user.

Video:

Gallery:

Image Image Image Image Image Image

Code:

#!/usr/bin/python3

# final projec.py
# By:      Martin Majkut, Omar Sanchez, Alex Klein, Khalil Payton, Sahana Karthik
# Date:    Apr. 16, 2018
# Purpose: to move a stick of butter across the table

def main():
    print('proportional_control.py')
    import time

#To initialise motors and sensors
    ev3    = Device('this')
    sensor_f = ev3.UltrasonicSensor('in2')
    sensor_b = ev3.UltrasonicSensor('in3')
    touch_1 = ev3.TouchSensor('in4')
    touch_2 = ev3.TouchSensor('in1')
    motorA  = ev3.LargeMotor('outC')
    motorB  = ev3.LargeMotor('outB')
    prongC = ev3.LargeMotor('outA')
    prongD = ev3.LargeMotor('outD')
    pos_C = prongC.position_sp
    print(pos_C)
    pos_D = prongD.position_sp
    print(pos_D)

#Define Constants
    maxSpeed  = 500         #Max Speed of Motor
    idealDist_butter = 3     #in, distance to stop at away from butter 
    slowDist_butter  = 12    #in, distance range to start slowing down on way to butter
    idealDist_hand = 2       #in, distance to stop at away from wall from hand
    slowDist_hand  = 12      #in, distance range to start slowing down on way to hand
    distance_butter  = 100   #in, current distance read by ultrasonic sensor to butter
    distance_hand  = 100     #in, current distance read by ultrasonic sensor to hand

#Proportional Control for Device To Move Forward:
    while distance_butter != idealDist_butter:
        distance_butter = sensor_f.distance_inches #Detect Distance Using Touch Sensor
        print(distance_butter)

        if abs(distance_butter - idealDist_butter) < slowDist_butter: 
            runSpeed = ((distance_butter - idealDist_butter)/slowDist_butter) * maxSpeed
            motorA.run_forever(speed_sp = runSpeed) 
            motorB.run_forever(speed_sp = runSpeed) 

        else:
            motorA.run_forever(speed_sp = maxSpeed)
            motorB.run_forever(speed_sp = maxSpeed)

    motorA.stop(stop_action="brake")
    motorB.stop(stop_action="brake")

#Move Prong Down:
    prongC.run_to_rel_pos(position_sp=(160), speed_sp=200, stop_action="coast")
    prongD.run_to_rel_pos(position_sp=(160), speed_sp=200, stop_action="coast")
    sleep(2.5)

#Move backwards to Hand when Touch Sensor is Pressed
    while distance_hand != idealDist_hand:
        distance_hand = sensor_b.distance_inches #Detect Distance Using Touch Sensor

        if abs(distance_hand - idealDist_hand) < slowDist_hand:
            runSpeed = ((distance_hand - idealDist_hand)/slowDist_hand) * maxSpeed
            motorA.run_forever(speed_sp = -runSpeed) 
            motorB.run_forever(speed_sp = -runSpeed) 
        else:
            motorA.run_forever(speed_sp = -maxSpeed)
            motorB.run_forever(speed_sp = -maxSpeed)
    motorA.stop(stop_action="brake")
    motorB.stop(stop_action="brake")

if __name__ == '__main__':
    main()