Hardware components | ||||||
| × | 3 | ||||
| × | 1 | ||||
Software apps and online services | ||||||
|
When we study robot`s algorithm in class, our teacher told to " do you wanna this contest ? " to us. We thought "It`s so interesting. " So, we joined this contest.
We thought " what is innovative robot ? ".One of us wondered if he could make a robot for deaf people. With Alexa, You can talk to people who are away. But, Alexa can only send voice, so it can not talk to deaf people. Hence, we made a robot which can communicate with them hand sign using EV3 to make them able to talk with Alexa.
How did we make this robotRobot
We used rubber bands for each finger joints to make a fist and threaded the fingers to make a paper when Motor actives. So, finger's angle is decided according to motor's number of rotations.
Thumb and middle finger must move width, so we install motor under them.
To make wrist movement, we made weight under body made with three EV3s and used motor.
Program
We used referred to Mission 3 programs in LEGO Mindstorms Voice Challenge mission and used common.js, package.json and util.js as they are.
https://www.hackster.io/alexagadgets/lego-mindstorms-voice-challenge-mission-3-4ed812
Alexa must send same data to each EV3s. So, we added endpointID in index.js and put them into global variable to send another const.
global.endpoint0 = apiResponse.endpoints[0].endpointId || [];
Util.putSessionAttribute(handlerInput, 'endpointId', global.endpoint0);
global.endpoint1 = apiResponse.endpoints[1].endpointId || [];
Util.putSessionAttribute(handlerInput, 'endpointId', global.endpoint1);
global.endpoint2 = apiResponse.endpoints[2].endpointId || [];
Util.putSessionAttribute(handlerInput, 'endpointId', global.endpoint2);
Main programs for EV3 actives As described below.
1, Receive data from Alexa by payload and send another function.
try:
payload = json.loads(directive.payload.decode("utf-8"))
time.sleep(0.5)
if payload["type"] == "word":
print("Get word:({})".format(payload["word"]), file=sys.stderr)
self.finger_control(payload["word"])
except KeyError:
print("Error")
2, Analyze words or sentences into each characters and move suitable for each characters.
def finger_control(self, word):
word_list = list(word.lower())
for i in word_list:
How does this robot activeEach alphabet has been expressed as follows:
Note that the letters "J" and "Z" should be expressed with list's movement not only the finger form, so please check its motion by the following videos.
The following videos demonstrate how the robot works:
The following photos are overall picture of robot:
const Alexa = require("ask-sdk-core");
const Util = require('./util');
const Common = require('./common');
const NAMESPACE = 'Custom.Mindstorms.Gadget';
const NAME_CONTROL = 'control';
const LaunchRequestHandler = {
canHandle(handlerInput) {
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'LaunchRequest';
},
handle: async function(handlerInput) {
let request = handlerInput.requestEnvelope;
let { apiEndpoint, apiAccessToken } = request.context.System;
let apiResponse = await Util.getConnectedEndpoints(apiEndpoint, apiAccessToken);
if ((apiResponse.endpoints || []).length === 0) {
return handlerInput.responseBuilder
.speak(`I couldn't find an EV3 Brick connected to this Echo device. Please check to make sure your EV3 Brick is connected, and try again.`)
.getResponse();
}
global.endpoint0 = apiResponse.endpoints[0].endpointId || [];
Util.putSessionAttribute(handlerInput, 'endpointId', global.endpoint0);
global.endpoint1 = apiResponse.endpoints[1].endpointId || [];
Util.putSessionAttribute(handlerInput, 'endpointId', global.endpoint1);
global.endpoint2 = apiResponse.endpoints[2].endpointId || [];
Util.putSessionAttribute(handlerInput, 'endpointId', global.endpoint2);
return handlerInput.responseBuilder
.speak("Welcome, you can start sign interpreter")
.reprompt("Awaiting commands")
.getResponse();
}
};
const WordIntentHandler = {
canHandle(handlerInput) {
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
&& Alexa.getIntentName(handlerInput.requestEnvelope) === 'SignlanguageIntent';
},
handle: function (handlerInput) {
let word = Alexa.getSlotValue(handlerInput.requestEnvelope, 'Word');
if (!word) {
return handlerInput.responseBuilder
.speak("Can you repeat that?")
.reprompt("What was that again?").getResponse();
}
let request = handlerInput.requestEnvelope;
let { apiEndpoint, apiAccessToken } = request.context.System;
let apiResponse = Util.getConnectedEndpoints(apiEndpoint, apiAccessToken);
let endpointId0 = global.endpoint0;
let directive0 = Util.build(endpointId0, NAMESPACE, NAME_CONTROL,
{
type: 'word',
word: word
});
handlerInput.responseBuilder
.speak(`${word}`)
.reprompt("awaiting word")
.addDirective(directive0)
let endpointId1 = global.endpoint1;
let directive1 = Util.build(endpointId1, NAMESPACE, NAME_CONTROL,
{
type: 'word',
word: word
});
handlerInput.responseBuilder
.speak(`${word}`)
.reprompt("awaiting word")
.addDirective(directive1)
let endpointId2 = global.endpoint2;
let directive2 = Util.build(endpointId2, NAMESPACE, NAME_CONTROL,
{
type: 'word',
word: word
});
return handlerInput.responseBuilder
.speak(`${word}`)
.reprompt("awaiting word")
.addDirective(directive2)
.getResponse();
}
};
exports.handler = Alexa.SkillBuilders.custom()
.addRequestHandlers(
LaunchRequestHandler,
WordIntentHandler,
)
.addRequestInterceptors(Common.RequestInterceptor)
.addErrorHandlers(
Common.ErrorHandler,
)
.lambda();
#!/usr/bin/env python3
# Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# You may not use this file except in compliance with the terms and conditions
# set forth in the accompanying LICENSE.TXT file.
#
# THESE MATERIALS ARE PROVIDED ON AN "AS IS" BASIS. AMAZON SPECIFICALLY DISCLAIMS, WITH
# RESPECT TO THESE MATERIALS, ALL WARRANTIES, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
# THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
import os
import sys
import time
import logging
import json
import threading
from enum import Enum
from agt import AlexaGadget
from ev3dev2.led import Leds
from ev3dev2.sound import Sound
from ev3dev2.motor import OUTPUT_A, OUTPUT_B, OUTPUT_C, OUTPUT_D, MoveTank, LargeMotor, MediumMotor, SpeedDPS
logging.basicConfig(level=logging.INFO, stream=sys.stdout, format='%(message)s')
logging.getLogger().addHandler(logging.StreamHandler(sys.stderr))
logger = logging.getLogger(__name__)
class MindstormsGadget(AlexaGadget):
def __init__(self):
super().__init__()
self.leds = Leds()
self.sound = Sound()
#SpeedDPS is degrees/s
self.speed = SpeedDPS(750)
self.wait_time_1 = int(5)
def on_connected(self, device_addr):
self.leds.set_color("LEFT", "GREEN")
self.leds.set_color("RIGHT", "GREEN")
logger.info("{} connected to Echo device".format(self.friendly_name))
def on_disconnected(self, device_addr):
self.leds.set_color("LEFT", "BLACK")
self.leds.set_color("RIGHT", "BLACK")
logger.info("{} disconnected from Echo device".format(self.friendly_name))
def move_3motors_simultaneous(self, port_1, port_2, port_3, degree):
def do():
LargeMotor(port_3).on_for_degrees(self.speed, degree)
threading.Thread(target=do).start()
MoveTank(port_1, port_2).on_for_degrees(self.speed, self.speed, degree)
def on_custom_mindstorms_gadget_control(self, directive):
try:
payload = json.loads(directive.payload.decode("utf-8"))
time.sleep(0.5)
if payload["type"] == "word":
print("Get word:({})".format(payload["word"]), file=sys.stderr)
self.finger_control(payload["word"])
except KeyError:
print("Error")
def finger_control(self, word):
word_list = list(word.lower())
for i in word_list:
word_char = i
if word_char == "a":
self.a()
elif word_char == "b":
self.b()
elif word_char == "c":
self.c()
elif word_char == "d":
self.d()
elif word_char == "e":
self.e()
elif word_char == "f":
self.f()
elif word_char == "g":
self.g()
elif word_char == "h":
self.h()
elif word_char == "i":
self.i()
elif word_char == "j":
self.j()
elif word_char == "k":
self.k()
elif word_char == "l":
self.l()
elif word_char == "m":
self.m()
elif word_char == "n":
self.n()
elif word_char == "o":
self.o()
elif word_char == "p":
self.p()
elif word_char == "q":
self.q()
elif word_char == "r":
self.r()
elif word_char == "s":
self.s()
elif word_char == "t":
self.t()
elif word_char == "u":
self.u()
elif word_char == "v":
self.v()
elif word_char == "w":
self.w()
elif word_char == "x":
self.x()
elif word_char == "y":
self.y()
elif word_char == "z":
self.z()
else:
pass
def a(self):
start_time = time.time()
self.move_3motors_simultaneous(OUTPUT_A, OUTPUT_B, OUTPUT_C, -1260)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
start_time = time.time()
self.move_3motors_simultaneous(OUTPUT_A, OUTPUT_B, OUTPUT_C, 1260)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
def b(self):
time.sleep(self.wait_time_1 * 2)
def c(self):
start_time = time.time()
self.move_3motors_simultaneous(OUTPUT_A, OUTPUT_B, OUTPUT_C, -540)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
start_time = time.time()
self.move_3motors_simultaneous(OUTPUT_A, OUTPUT_B, OUTPUT_C, 540)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
def d(self):
start_time = time.time()
MoveTank(OUTPUT_B, OUTPUT_C).on_for_degrees(self.speed, self.speed, -1260)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
start_time = time.time()
MoveTank(OUTPUT_B, OUTPUT_C).on_for_degrees(self.speed, self.speed, 1260)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
def e(self):
start_time = time.time()
def e_thread_1():
LargeMotor(OUTPUT_C).on_for_degrees(self.speed, -1260)
threading.Thread(target=e_thread_1).start()
MoveTank(OUTPUT_A, OUTPUT_B).on_for_degrees(self.speed, self.speed, -630)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
start_time = time.time()
def e_thread_2():
LargeMotor(OUTPUT_C).on_for_degrees(self.speed, 1260)
threading.Thread(target=e_thread_2).start()
MoveTank(OUTPUT_A, OUTPUT_B).on_for_degrees(self.speed, self.speed, 630)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
def f(self):
start_time = time.time()
time.sleep(1)
LargeMotor(OUTPUT_A).on_for_degrees(self.speed, -1260)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
start_time = time.time()
LargeMotor(OUTPUT_A).on_for_degrees(self.speed, 1260)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
def g(self):
start_time = time.time()
MoveTank(OUTPUT_B, OUTPUT_C).on_for_degrees(self.speed, self.speed, -1260)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
start_time = time.time()
MoveTank(OUTPUT_B, OUTPUT_C).on_for_degrees(self.speed, self.speed, 1260)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
def h(self):
start_time = time.time()
LargeMotor(OUTPUT_C).on_for_degrees(self.speed, -1260)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
start_time = time.time()
LargeMotor(OUTPUT_C).on_for_degrees(self.speed, 1260)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
def i(self):
start_time = time.time()
self.move_3motors_simultaneous(OUTPUT_A, OUTPUT_B, OUTPUT_C, -1260)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
start_time = time.time()
self.move_3motors_simultaneous(OUTPUT_A, OUTPUT_B, OUTPUT_C, 1260)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
def j(self):
start_time = time.time()
self.move_3motors_simultaneous(OUTPUT_A, OUTPUT_B, OUTPUT_C, -1260)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
start_time = time.time()
self.move_3motors_simultaneous(OUTPUT_A, OUTPUT_B, OUTPUT_C, 1260)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
def k(self):
start_time = time.time()
LargeMotor(OUTPUT_C).on_for_degrees(self.speed, -1260)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
start_time = time.time()
LargeMotor(OUTPUT_C).on_for_degrees(self.speed, 1260)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
def l(self):
start_time = time.time()
MoveTank(OUTPUT_B, OUTPUT_C).on_for_degrees(self.speed, self.speed, -1260)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
start_time = time.time()
MoveTank(OUTPUT_B, OUTPUT_C).on_for_degrees(self.speed, self.speed, 1260)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
def m(self):
start_time = time.time()
self.move_3motors_simultaneous(OUTPUT_A, OUTPUT_B, OUTPUT_C, -630)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
start_time = time.time()
self.move_3motors_simultaneous(OUTPUT_A, OUTPUT_B, OUTPUT_C, 630)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
def n(self):
start_time = time.time()
LargeMotor(OUTPUT_C).on_for_degrees(self.speed, -1260)
MoveTank(OUTPUT_A, OUTPUT_B).on_for_degrees(self.speed, self.speed, -630)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
start_time = time.time()
LargeMotor(OUTPUT_C).on_for_degrees(self.speed, 1260)
MoveTank(OUTPUT_A, OUTPUT_B).on_for_degrees(self.speed, self.speed, 630)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
def o(self):
start_time = time.time()
self.move_3motors_simultaneous(OUTPUT_A, OUTPUT_B, OUTPUT_C, -630)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
start_time = time.time()
self.move_3motors_simultaneous(OUTPUT_A, OUTPUT_B, OUTPUT_C, 630)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
def p(self):
start_time = time.time()
def do():
LargeMotor(OUTPUT_C).on_for_degrees(self.speed, -1260)
threading.Thread(target=do).start()
LargeMotor(OUTPUT_B).on_for_degrees(self.speed, -630)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
start_time = time.time()
def reset():
LargeMotor(OUTPUT_C).on_for_degrees(self.speed, 1260)
threading.Thread(target=reset).start()
LargeMotor(OUTPUT_B).on_for_degrees(self.speed, 630)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
def q(self):
start_time = time.time()
def do():
LargeMotor(OUTPUT_C).on_for_degrees(self.speed, -1260)
threading.Thread(target=do).start()
LargeMotor(OUTPUT_B).on_for_degrees(self.speed, -900)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
start_time = time.time()
def reset():
LargeMotor(OUTPUT_C).on_for_degrees(self.speed, 1260)
threading.Thread(target=reset).start()
LargeMotor(OUTPUT_B).on_for_degrees(self.speed, 900)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
def r(self):
start_time = time.time()
def do():
MoveTank(OUTPUT_A, OUTPUT_B).on_for_degrees(self.speed, self.speed, -270)
threading.Thread(target=do).start()
LargeMotor(OUTPUT_C).on_for_degrees(self.speed, -1260)
MediumMotor(OUTPUT_D).on_for_degrees(SpeedDPS(200), 50)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
start_time = time.time()
def reset():
MoveTank(OUTPUT_A, OUTPUT_B).on_for_degrees(self.speed, self.speed, 270)
threading.Thread(target=reset).start()
LargeMotor(OUTPUT_C).on_for_degrees(self.speed, 1260)
MediumMotor(OUTPUT_D).on_for_degrees(SpeedDPS(200), -50)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
def s(self):
start_time = time.time()
self.move_3motors_simultaneous(OUTPUT_A, OUTPUT_B, OUTPUT_C, -1260)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
start_time = time.time()
self.move_3motors_simultaneous(OUTPUT_A, OUTPUT_B, OUTPUT_C, 1260)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
def t(self):
start_time = time.time()
MoveTank(OUTPUT_B, OUTPUT_C).on_for_degrees(self.speed, self.speed, -1260)
LargeMotor(OUTPUT_A).on_for_degrees(self.speed, -630)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
start_time = time.time()
LargeMotor(OUTPUT_A).on_for_degrees(self.speed, 630)
MoveTank(OUTPUT_B, OUTPUT_C).on_for_degrees(self.speed, self.speed, 1260)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
def u(self):
start_time = time.time()
LargeMotor(OUTPUT_C).on_for_degrees(self.speed, -1260)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
start_time = time.time()
LargeMotor(OUTPUT_C).on_for_degrees(self.speed, 1260)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
def v(self):
start_time = time.time()
def do():
LargeMotor(OUTPUT_C).on_for_degrees(self.speed, -1260)
threading.Thread(target=do).start()
MediumMotor(OUTPUT_D).on_for_degrees(self.speed, -45)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
start_time = time.time()
def reset():
LargeMotor(OUTPUT_C).on_for_degrees(self.speed, 1260)
threading.Thread(target=reset).start()
MediumMotor(OUTPUT_D).on_for_degrees(self.speed, 45)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
def w(self):
time.sleep(self.wait_time_1 * 2)
def x(self):
start_time = time.time()
def do():
MoveTank(OUTPUT_B, OUTPUT_C).on_for_degrees(self.speed, self.speed, -1260)
threading.Thread(target=do).start()
LargeMotor(OUTPUT_A).on_for_degrees(self.speed, -300)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
start_time = time.time()
def reset():
MoveTank(OUTPUT_B, OUTPUT_C).on_for_degrees(self.speed, self.speed, 1260)
threading.Thread(target=reset).start()
LargeMotor(OUTPUT_A).on_for_degrees(self.speed, 300)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
def y(self):
start_time = time.time()
self.move_3motors_simultaneous(OUTPUT_A, OUTPUT_B, OUTPUT_C, -1260)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
start_time = time.time()
self.move_3motors_simultaneous(OUTPUT_A, OUTPUT_B, OUTPUT_C, 1260)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
def z(self):
start_time = time.time()
MoveTank(OUTPUT_B, OUTPUT_C).on_for_degrees(self.speed, self.speed, -1260)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
start_time = time.time()
MoveTank(OUTPUT_B, OUTPUT_C).on_for_degrees(self.speed, self.speed, 1260)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
if __name__ == '__main__':
gadget = MindstormsGadget()
os.system('setfont Lat7-Terminus12x6')
gadget.leds.set_color("LEFT", "BLACK")
gadget.leds.set_color("RIGHT", "BLACK")
gadget.sound.play_song((('C4', 'e'), ('D4', 'e'), ('E5', 'q')))
gadget.leds.set_color("LEFT", "GREEN")
gadget.leds.set_color("RIGHT", "GREEN")
gadget.main()
gadget.sound.play_song((('E5', 'e'), ('C4', 'e')))
gadget.leds.set_color("LEFT", "BLACK")
gadget.leds.set_color("RIGHT", "BLACK")
#!/usr/bin/env python3
# Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# You may not use this file except in compliance with the terms and conditions
# set forth in the accompanying LICENSE.TXT file.
#
# THESE MATERIALS ARE PROVIDED ON AN "AS IS" BASIS. AMAZON SPECIFICALLY DISCLAIMS, WITH
# RESPECT TO THESE MATERIALS, ALL WARRANTIES, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
# THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
import os
import sys
import time
import logging
import json
import threading
from enum import Enum
from agt import AlexaGadget
from ev3dev2.led import Leds
from ev3dev2.sound import Sound
from ev3dev2.motor import OUTPUT_A, OUTPUT_B, OUTPUT_C, OUTPUT_D, MoveTank, LargeMotor, MediumMotor, SpeedDPS
logging.basicConfig(level=logging.INFO, stream=sys.stdout, format='%(message)s')
logging.getLogger().addHandler(logging.StreamHandler(sys.stderr))
logger = logging.getLogger(__name__)
class MindstormsGadget(AlexaGadget):
def __init__(self):
super().__init__()
self.leds = Leds()
self.sound = Sound()
#SpeedDPS is degrees/s
self.speed = SpeedDPS(750)
self.speed_med = SpeedDPS(200)
self.wait_time_1 = int(5)
self.wait_time_2 = int(5)
def on_connected(self, device_addr):
self.leds.set_color("LEFT", "GREEN")
self.leds.set_color("RIGHT", "GREEN")
logger.info("{} connected to Echo device".format(self.friendly_name))
def on_disconnected(self, device_addr):
self.leds.set_color("LEFT", "BLACK")
self.leds.set_color("RIGHT", "BLACK")
logger.info("{} disconnected from Echo device".format(self.friendly_name))
def move_3motors_simultaneous(self, port_1, port_2, port_3, degree):
def do():
LargeMotor(port_3).on_for_degrees(self.speed, degree)
threading.Thread(target=do).start()
MoveTank(port_1, port_2).on_for_degrees(self.speed, self.speed, degree)
def move_different_motor(self, degree_a, degree_b):
def do():
MediumMotor(OUTPUT_D).on_for_degrees(self.speed_med, degree_b)
threading.Thread(target=do).start()
LargeMotor(OUTPUT_A).on_for_degrees(self.speed, degree_a)
def on_custom_mindstorms_gadget_control(self, directive):
try:
payload = json.loads(directive.payload.decode("utf-8"))
if payload["type"] == "word":
print("Get word:({})".format(payload["word"]), file=sys.stderr)
self.finger_control(payload["word"])
except KeyError:
print("Error")
def finger_control(self, word):
word_list = list(word.lower())
for i in word_list:
word_char = i
if word_char == "a":
self.a()
elif word_char == "b":
self.b()
elif word_char == "c":
self.c()
elif word_char == "d":
self.d()
elif word_char == "e":
self.e()
elif word_char == "f":
self.f()
elif word_char == "g":
self.g()
elif word_char == "h":
self.h()
elif word_char == "i":
self.i()
elif word_char == "j":
self.j()
elif word_char == "k":
self.k()
elif word_char == "l":
self.l()
elif word_char == "m":
self.m()
elif word_char == "n":
self.n()
elif word_char == "o":
self.o()
elif word_char == "p":
self.p()
elif word_char == "q":
self.q()
elif word_char == "r":
self.r()
elif word_char == "s":
self.s()
elif word_char == "t":
self.t()
elif word_char == "u":
self.u()
elif word_char == "v":
self.v()
elif word_char == "w":
self.w()
elif word_char == "x":
self.x()
elif word_char == "y":
self.y()
elif word_char == "z":
self.z()
else:
pass
def a(self):
start_time = time.time()
LargeMotor(OUTPUT_B).on_for_degrees(self.speed, -1260)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
start_time = time.time()
LargeMotor(OUTPUT_B).on_for_degrees(self.speed, 1260)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
def b(self):
start_time = time.time()
self.move_different_motor(-630, 89)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
start_time = time.time()
self.move_different_motor(630, -89)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
def c(self):
start_time = time.time()
def do():
MediumMotor(OUTPUT_D).on_for_degrees(self.speed_med, 45)
threading.Thread(target=do).start()
LargeMotor(OUTPUT_B).on_for_degrees(self.speed, -540)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
start_time = time.time()
def reset():
MediumMotor(OUTPUT_D).on_for_degrees(self.speed_med, -45)
threading.Thread(target=reset).start()
LargeMotor(OUTPUT_B).on_for_degrees(self.speed, 540)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
def d(self):
start_time = time.time()
def do():
self.move_different_motor(-900, 89)
threading.Thread(target=do).start()
LargeMotor(OUTPUT_B).on_for_degrees(self.speed, -1260)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
start_time = time.time()
def reset():
self.move_different_motor(900, -89)
threading.Thread(target=reset).start()
LargeMotor(OUTPUT_B).on_for_degrees(self.speed, 1260)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
def e(self):
start_time = time.time()
def do():
self.move_different_motor(-900, 89)
threading.Thread(target=do).start()
LargeMotor(OUTPUT_B).on_for_degrees(self.speed, -1260)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
start_time = time.time()
def reset():
self.move_different_motor(900, -89)
threading.Thread(target=reset).start()
LargeMotor(OUTPUT_B).on_for_degrees(self.speed, 1260)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
def f(self):
start_time = time.time()
self.move_different_motor(-900, 89)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
start_time = time.time()
time.sleep(1)
self.move_different_motor(900, -89)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
def g(self):
start_time = time.time()
def do():
self.move_different_motor(-630, 89)
threading.Thread(target=do).start()
LargeMotor(OUTPUT_B).on_for_degrees(self.speed, -1260)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
start_time = time.time()
def reset():
self.move_different_motor(630, -89)
threading.Thread(target=reset).start()
LargeMotor(OUTPUT_B).on_for_degrees(self.speed, 1260)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
def h(self):
start_time = time.time()
def do():
self.move_different_motor(-900, 89)
threading.Thread(target=do).start()
LargeMotor(OUTPUT_B).on_for_degrees(self.speed, -1260)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
start_time = time.time()
def reset():
self.move_different_motor(900, -89)
threading.Thread(target=reset).start()
LargeMotor(OUTPUT_B).on_for_degrees(self.speed, 1260)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
def i(self):
start_time = time.time()
self.move_different_motor(-900, 22)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
start_time = time.time()
self.move_different_motor(900, -22)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
def j(self):
start_time = time.time()
self.move_different_motor(-900, 22)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
start_time = time.time()
self.move_different_motor(900, -22)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
def k(self):
start_time = time.time()
def do():
self.move_different_motor(-900, 89)
threading.Thread(target=do).start()
LargeMotor(OUTPUT_B).on_for_degrees(self.speed, -1260)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
start_time = time.time()
def reset():
self.move_different_motor(900, -89)
threading.Thread(target=reset).start()
LargeMotor(OUTPUT_B).on_for_degrees(self.speed, 1260)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
def l(self):
start_time = time.time()
def do():
self.move_different_motor(-500, -89)
threading.Thread(target=do).start()
LargeMotor(OUTPUT_B).on_for_degrees(self.speed, -1260)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
start_time = time.time()
def reset():
self.move_different_motor(500, 89)
threading.Thread(target=reset).start()
LargeMotor(OUTPUT_B).on_for_degrees(self.speed, 1260)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
def m(self):
start_time = time.time()
def do():
self.move_different_motor(-900, 89)
threading.Thread(target=do).start()
LargeMotor(OUTPUT_B).on_for_degrees(self.speed, -1260)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
start_time = time.time()
LargeMotor(OUTPUT_B).on_for_degrees(self.speed, 1260)
self.move_different_motor(900, -89)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
def n(self):
start_time = time.time()
def do():
self.move_different_motor(-900, 89)
threading.Thread(target=do).start()
LargeMotor(OUTPUT_B).on_for_degrees(self.speed, -1260)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
start_time = time.time()
LargeMotor(OUTPUT_B).on_for_degrees(self.speed, 1260)
self.move_different_motor(900, -89)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
def o(self):
start_time = time.time()
def do():
self.move_different_motor(-630, 10)
threading.Thread(target=do).start()
LargeMotor(OUTPUT_B).on_for_degrees(self.speed, -630)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
start_time = time.time()
def reset():
self.move_different_motor(630, -10)
threading.Thread(target=reset).start()
LargeMotor(OUTPUT_B).on_for_degrees(self.speed, 630)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
def p(self):
start_time = time.time()
def do():
self.move_different_motor(-270, 89)
threading.Thread(target=do).start()
LargeMotor(OUTPUT_B).on_for_degrees(self.speed, -1260)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
start_time = time.time()
def reset():
self.move_different_motor(270, -89)
threading.Thread(target=reset).start()
LargeMotor(OUTPUT_B).on_for_degrees(self.speed, 1260)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
def q(self):
start_time = time.time()
def do():
self.move_different_motor(-600, 89)
threading.Thread(target=do).start()
LargeMotor(OUTPUT_B).on_for_degrees(self.speed, -1260)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
start_time = time.time()
def reset():
self.move_different_motor(600, -89)
threading.Thread(target=reset).start()
LargeMotor(OUTPUT_B).on_for_degrees(self.speed, 1260)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
def r(self):
start_time = time.time()
def do():
self.move_different_motor(-900, 89)
threading.Thread(target=do).start()
LargeMotor(OUTPUT_B).on_for_degrees(self.speed, -1260)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
start_time = time.time()
def reset():
self.move_different_motor(900, -89)
threading.Thread(target=reset).start()
LargeMotor(OUTPUT_B).on_for_degrees(self.speed, 1260)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
def s(self):
start_time = time.time()
LargeMotor(OUTPUT_B).on_for_degrees(self.speed, -1260)
self.move_different_motor(-900, 89)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
start_time = time.time()
self.move_different_motor(900, -89)
LargeMotor(OUTPUT_B).on_for_degrees(self.speed, 1260)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
def t(self):
start_time = time.time()
def do():
self.move_different_motor(-900, 89)
threading.Thread(target=do).start()
LargeMotor(OUTPUT_B).on_for_degrees(self.speed, -1260)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
start_time = time.time()
LargeMotor(OUTPUT_B).on_for_degrees(self.speed, 1260)
self.move_different_motor(900, -89)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
def u(self):
start_time = time.time()
def do():
self.move_different_motor(-900, 89)
threading.Thread(target=do).start()
LargeMotor(OUTPUT_B).on_for_degrees(self.speed, -1260)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
start_time = time.time()
def reset():
self.move_different_motor(900, -89)
threading.Thread(target=reset).start()
LargeMotor(OUTPUT_B).on_for_degrees(self.speed, 1260)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
def v(self):
start_time = time.time()
def do():
self.move_different_motor(-900, 89)
threading.Thread(target=do).start()
LargeMotor(OUTPUT_B).on_for_degrees(self.speed, -1260)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
start_time = time.time()
def reset():
self.move_different_motor(900, -89)
threading.Thread(target=reset).start()
LargeMotor(OUTPUT_B).on_for_degrees(self.speed, 1260)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
def w(self):
start_time = time.time()
def do():
self.move_different_motor(-900, 89)
threading.Thread(target=do).start()
LargeMotor(OUTPUT_B).on_for_degrees(self.speed, -1260)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
start_time = time.time()
def reset():
self.move_different_motor(900, -89)
threading.Thread(target=reset).start()
LargeMotor(OUTPUT_B).on_for_degrees(self.speed, 1260)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
def x(self):
start_time = time.time()
def do():
self.move_different_motor(-900, 89)
threading.Thread(target=do).start()
LargeMotor(OUTPUT_B).on_for_degrees(self.speed, -1260)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
start_time = time.time()
def reset():
self.move_different_motor(900, -89)
threading.Thread(target=reset).start()
LargeMotor(OUTPUT_B).on_for_degrees(self.speed, 1260)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
def y(self):
time.sleep(self.wait_time_1 * 2)
def z(self):
start_time = time.time()
def do():
self.move_different_motor(-900, 89)
threading.Thread(target=do).start()
LargeMotor(OUTPUT_B).on_for_degrees(self.speed, -1260)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
start_time = time.time()
def reset():
self.move_different_motor(900, -89)
threading.Thread(target=reset).start()
LargeMotor(OUTPUT_B).on_for_degrees(self.speed, 1260)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
if __name__ == '__main__':
gadget = MindstormsGadget()
os.system('setfont Lat7-Terminus12x6')
gadget.leds.set_color("LEFT", "BLACK")
gadget.leds.set_color("RIGHT", "BLACK")
gadget.sound.play_song((('C4', 'e'), ('D4', 'e'), ('E5', 'q')))
gadget.leds.set_color("LEFT", "GREEN")
gadget.leds.set_color("RIGHT", "GREEN")
gadget.main()
gadget.sound.play_song((('E5', 'e'), ('C4', 'e')))
gadget.leds.set_color("LEFT", "BLACK")
gadget.leds.set_color("RIGHT", "BLACK")
#!/usr/bin/env python3
# Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# You may not use this file except in compliance with the terms and conditions
# set forth in the accompanying LICENSE.TXT file.
#
# THESE MATERIALS ARE PROVIDED ON AN "AS IS" BASIS. AMAZON SPECIFICALLY DISCLAIMS, WITH
# RESPECT TO THESE MATERIALS, ALL WARRANTIES, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
# THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
import os
import sys
import time
import logging
import json
import threading
from enum import Enum
from agt import AlexaGadget
from ev3dev2.led import Leds
from ev3dev2.sound import Sound
from ev3dev2.motor import OUTPUT_A, OUTPUT_B, OUTPUT_C, OUTPUT_D, MoveTank, LargeMotor, MediumMotor, SpeedDPS
logging.basicConfig(level=logging.INFO, stream=sys.stdout, format='%(message)s')
logging.getLogger().addHandler(logging.StreamHandler(sys.stderr))
logger = logging.getLogger(__name__)
class MindstormsGadget(AlexaGadget):
def __init__(self):
super().__init__()
self.leds = Leds()
self.sound = Sound()
#SpeedDPS is degrees/s
self.speed = SpeedDPS(750)
self.wait_time_1 = int(5)
self.wait_time_2 = int(5)
def on_connected(self, device_addr):
self.leds.set_color("LEFT", "GREEN")
self.leds.set_color("RIGHT", "GREEN")
logger.info("{} connected to Echo device".format(self.friendly_name))
def on_disconnected(self, device_addr):
self.leds.set_color("LEFT", "BLACK")
self.leds.set_color("RIGHT", "BLACK")
logger.info("{} disconnected from Echo device".format(self.friendly_name))
def move_3motors_simultaneous(self, port_1, port_2, port_3, degree):
def do():
LargeMotor(port_3).on_for_degrees(self.speed, degree)
threading.Thread(target=do).start()
MoveTank(port_1, port_2).on_for_degrees(self.speed, self.speed, degree)
def on_custom_mindstorms_gadget_control(self, directive):
try:
payload = json.loads(directive.payload.decode("utf-8"))
time.sleep(0.2)
if payload["type"] == "word":
print("Get word:({})".format(payload["word"]), file=sys.stderr)
self.finger_control(payload["word"])
except KeyError:
print("Error")
def finger_control(self, word):
word_list = list(word.lower())
for i in word_list:
word_char = i
if word_char == "a":
self.a()
elif word_char == "b":
self.b()
elif word_char == "c":
self.c()
elif word_char == "d":
self.d()
elif word_char == "e":
self.e()
elif word_char == "f":
self.f()
elif word_char == "g":
self.g()
elif word_char == "h":
self.h()
elif word_char == "i":
self.i()
elif word_char == "j":
self.j()
elif word_char == "k":
self.k()
elif word_char == "l":
self.l()
elif word_char == "m":
self.m()
elif word_char == "n":
self.n()
elif word_char == "o":
self.o()
elif word_char == "p":
self.p()
elif word_char == "q":
self.q()
elif word_char == "r":
self.r()
elif word_char == "s":
self.s()
elif word_char == "t":
self.t()
elif word_char == "u":
self.u()
elif word_char == "v":
self.v()
elif word_char == "w":
self.w()
elif word_char == "x":
self.x()
elif word_char == "y":
self.y()
elif word_char == "z":
self.z()
else:
pass
def a(self):
time.sleep(self.wait_time_1 * 2)
def b(self):
time.sleep(self.wait_time_1 * 2)
def c(self):
start_time = time.time()
LargeMotor(OUTPUT_A).on_for_degrees(SpeedDPS(1000), -1200)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
start_time = time.time()
LargeMotor(OUTPUT_A).on_for_degrees(SpeedDPS(1000), 1200)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
def d(self):
time.sleep(self.wait_time_1 * 2)
def e(self):
time.sleep(self.wait_time_1 * 2)
def f(self):
time.sleep(self.wait_time_1 * 2)
def g(self):
start_time = time.time()
LargeMotor(OUTPUT_A).on_for_degrees(SpeedDPS(1000), -1200)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
start_time = time.time()
LargeMotor(OUTPUT_A).on_for_degrees(SpeedDPS(1000), 1200)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
def h(self):
start_time = time.time()
LargeMotor(OUTPUT_A).on_for_degrees(SpeedDPS(1000), -1200)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
start_time = time.time()
LargeMotor(OUTPUT_A).on_for_degrees(SpeedDPS(1000), 1200)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
def i(self):
time.sleep(self.wait_time_1 * 2)
def j(self):
start_time = time.time()
LargeMotor(OUTPUT_A).on_for_degrees(SpeedDPS(1000), -1200)
LargeMotor(OUTPUT_A).on_for_degrees(SpeedDPS(1000), 1200)
end_time = time.time()
time.sleep(self.wait_time_1 * 2 - end_time + start_time)
def k(self):
time.sleep(self.wait_time_1 * 2)
def l(self):
time.sleep(self.wait_time_1 * 2)
def m(self):
time.sleep(self.wait_time_1 * 2)
def n(self):
time.sleep(self.wait_time_1 * 2)
def o(self):
time.sleep(self.wait_time_1 * 2)
def p(self):
start_time = time.time()
LargeMotor(OUTPUT_A).on_for_degrees(SpeedDPS(1000), -1200)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
start_time = time.time()
LargeMotor(OUTPUT_A).on_for_degrees(SpeedDPS(1000), 1200)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
def q(self):
start_time = time.time()
LargeMotor(OUTPUT_A).on_for_degrees(SpeedDPS(1000), -1200)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
start_time = time.time()
LargeMotor(OUTPUT_A).on_for_degrees(SpeedDPS(1000), 1200)
end_time = time.time()
time.sleep(self.wait_time_1 - end_time + start_time)
def r(self):
time.sleep(self.wait_time_1 * 2)
def s(self):
time.sleep(self.wait_time_1 * 2)
def t(self):
time.sleep(self.wait_time_1 * 2)
def u(self):
time.sleep(self.wait_time_1 * 2)
def v(self):
time.sleep(self.wait_time_1 * 2)
def w(self):
time.sleep(self.wait_time_1 * 2)
def x(self):
time.sleep(self.wait_time_1 * 2)
def y(self):
time.sleep(self.wait_time_1 * 2)
def z(self):
start_time = time.time()
LargeMotor(OUTPUT_A).on_for_degrees(SpeedDPS(1000), -1200)
LargeMotor(OUTPUT_A).on_for_degrees(SpeedDPS(1000), 1200)
end_time = time.time()
time.sleep(self.wait_time_1 * 2 - end_time + start_time)
if __name__ == '__main__':
gadget = MindstormsGadget()
os.system('setfont Lat7-Terminus12x6')
gadget.leds.set_color("LEFT", "BLACK")
gadget.leds.set_color("RIGHT", "BLACK")
gadget.sound.play_song((('C4', 'e'), ('D4', 'e'), ('E5', 'q')))
gadget.leds.set_color("LEFT", "GREEN")
gadget.leds.set_color("RIGHT", "GREEN")
gadget.main()
gadget.sound.play_song((('E5', 'e'), ('C4', 'e')))
gadget.leds.set_color("LEFT", "BLACK")
gadget.leds.set_color("RIGHT", "BLACK")
{
"interactionModel": {
"languageModel": {
"invocationName": "sign language",
"intents": [
{
"name": "AMAZON.CancelIntent",
"samples": []
},
{
"name": "AMAZON.HelpIntent",
"samples": []
},
{
"name": "AMAZON.StopIntent",
"samples": []
},
{
"name": "AMAZON.NavigateHomeIntent",
"samples": []
},
{
"name": "SignlanguageIntent",
"slots": [
{
"name": "Word",
"type": "WordType"
}
],
"samples": [
"{Word}"
]
}
],
"types": [
{
"name": "WordType",
"values": [
{
"name": {
"value": "hello"
}
},
{
"name": {
"value": "hi"
}
},
{
"name": {
"value": "goodbye"
}
},
{
"name": {
"value": "how are you"
}
}
]
}
]
}
}
}
Comments