This is a LEGO MINDSTORMS Spirograph that is controlled by an Amazon Alexa Echo Show. This fun project brings STEAM to life in a user-friendly manner, allowing children to interact with their drawing robot orally. The user picks the design he/she wants to print and asks Alexa to draw it.
How it WorksEach design is created by changing the speed and position of each of the motors. When a user asks for a design, the robot sets the speed of each motor and runs for a certain time.
CodeThe code below chooses the percent speed of each motor based on the pattern ID. It then runs the motors at that speed for 25 seconds.
...
tank_drive = MoveTank(OUTPUT_A, OUTPUT_C)
turnTable = LargeMotor(OUTPUT_D)
if pattern == 1 :
D=30
A=30
C=30
if pattern == 2 :
D=7
A=50
C=0
if pattern == 3 :
D=30
A=-30
C=30
if pattern == 4 :
D=30
A=-30
C=30
if pattern == 5 :
D=10
A=-20
C=20
turnTable.on(SpeedPercent(D))
tank_drive.on(C, A)
time.sleep(25) # draw pattern for 25 seconds before stopping
turnTable.on(SpeedPercent(0))
tank_drive.on(0, 0)
...
This
code is called using the Alexa API:
...
def _draw(self, shape):
"""
Handles drawing command from the directive.
:param shape: the id of the shape/pattern to draw (int 1-5)
"""
print("drawing shape #"+str(shape))
# Call spirograph program from spirograph.py
spirograph.spirograph(shape)
...
When the Alexa call is activated, this function is run with the id of the desired pattern as an input.
The Node JS lambda file that runs on the Amazon AWS servers takes the spoken command to send to the EV3 over Bluetooth:
...
const DrawIntentHandler = {
canHandle(handlerInput) {
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
&& Alexa.getIntentName(handlerInput.requestEnvelope) === 'DrawIntent';
},
handle: function (handlerInput) {
const request = handlerInput.requestEnvelope;
let pattern = Alexa.getSlotValue(handlerInput.requestEnvelope, 'Pattern');
const attributesManager = handlerInput.attributesManager;
const endpointId = attributesManager.getSessionAttributes().endpointId || [];
// Construct the directive with the payload containing the id for the pattern
const directive = Util.build(endpointId, NAMESPACE, NAME_CONTROL,
{
type: 'draw',
pattern: pattern
});
const speechOutput = (pattern === 0)
? "Applying none"
: `Drawing pattern ${pattern}`;
return handlerInput.responseBuilder
.speak(speechOutput)
.reprompt("awaiting command")
.addDirective(directive)
.getResponse();
}
};
...
The spoken command is in the format "Alexa, open spirograph." Then, "Draw pattern {id of pattern}", where the id is an integer from 1 to 5. The Node JS processes the command and then the Python draws based on which pattern the user specified.
DesignThe robot is created using one LEGO MINDSTORMS EV3 brick and three large motors. The design is intended to be simple so that a beginner robot maker can create it. The turntable is made up of four Technic, Gear Rack 11 x 11 Curved elements, made to form a large circle or inverted gear. Two more gears are placed inside the inverted gear and are attached to a large motor. The platform that holds the paper is attached to the inverted gear. The marker is held in place by two technic liftarms each attached to a large motor on hinged joints. As the motors spin at different rates, the marker travels in a unique way across the paper. The turntable spins to create a circular drawing.
Comments