Skip to content

Commit

Permalink
Move dialogue out of sources, add backend selector
Browse files Browse the repository at this point in the history
Closes #13.
  • Loading branch information
PeterBowman committed Jan 3, 2024
1 parent aa60663 commit 53488e1
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 50 deletions.
101 changes: 55 additions & 46 deletions programs/DialogueManager/DialogueManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

#include "DialogueManager.hpp"

#include <array>
#include <exception>

#include <yarp/os/LogStream.h>
#include <yarp/os/Property.h>
#include <yarp/os/SystemClock.h>

using namespace roboticslab;
Expand All @@ -13,87 +15,94 @@ namespace
{
class ThreadTerminator : public std::exception {};

const std::unordered_map<std::string, std::string> englishSentences = {
{"presentation_01", "Hi. My name is TEO. I am a humanoid robot designed in the University Carlos Tercero of Madrid. I am 10 years old. My size is 1 70 meters and my weight is 60 kilograms."},
{"presentation_02", "My purpose, is to enable our researchers, to reach new achievements and discoveries, within the robotics area."},
{"composition_01", "I am mainly built, of aluminum, plastic and carbon fiber."},
{"composition_02", "I have 28 degrees, of freedom, that allow me to move freely, being able to do, such human tasks as walking, identifying and manipulating objects, doing household chores, ironing, serving as a waiter, etc."},
{"composition_03", "In my head, I have implemented two cameras, with which, I can detect objects, and human faces. Also, I can detect their distance and depth."},
{"composition_04", "As you can see, I have three computers, in my chest, each dedicated to a different task."},
{"composition_05_01", "The computer on my right, serves me, to capture and process the data collected from my sensors."},
{"composition_05_02", "While, the computer on my left, is dedicated, to the tasks of, manipulation and locomotion. It is the computer that plans and gives life to each of my movements"},
{"composition_05_03", "The computer that is located, just at the top, is dedicated to the processing of vision. In this way, each computer, is dedicated to processing a part of the task that I will perform."},
{"composition_06", "Both of them, the manipulation computer, and the locomotion computer, are connected to a communication network called, can bus, which sends all the motion commands to each of my motors."},
{"composition_07", "I also have movement, inertial, and force sensors, that allow me to detect the weight, and pressure exerted on my joints. These sensors allow, for example, to stay in balance, while walking or standing up."},
{"purpose_01", "All the components that make up everything I am, as well as the programs that allow me to perform all these tasks, have been developed by teachers and students from this university. The main mission is to discover and advance together in the field of robotics."},
{"purpose_02", "For now, I am only a prototype, dedicated to research, so, I can not be sold in any store. Also, my price would be too expensive to be bought."},
{"ending_01", "These, is the end of my presentation. I hope you liked it, and if you want, you can take a picture with me. Nice to meet you."},
};

const std::unordered_map<std::string, std::string> spanishSentences = {
{"presentation_01", "Hola. Mi nombre es TEO y soy un drobot humanoide diseñado en la Universidad Carlos Tercero de Madrid. Tengo unos 10 años desde que me crearon. Mido 1 70 y peso 60 kilos."},
{"presentation_02", "He sido diseñado con el propósito de ayudar a la investigación y a conseguir nuevos logros y descubrimientos dentro del área de la drobótica."},
{"composition_01", "Mis piezas están construidas principalmente de aluminio, plástico y fibra de carbono."},
{"composition_02", "Dispongo de 28 grados de libertad que me permiten moverme con soltura, siendo capaz de hacer tareas tan humanas como andar, identificar y manipular objetos, realizar tareas del hogar, planchar, servir de camarero, etcétera."},
{"composition_03", "En mi cabeza tengo implementadas dos cámaras con las cuales puedo detectar objetos y caras humanas, así como determinar la distancia y profundidad a la que se encuentran."},
{"composition_04", "Como podéis ver, dispongo en el interior de mi pecho de tres ordenadores, cada uno dedicado a una tarea distinta."},
{"composition_05_01", "El ordenador de mi derecha me sirve para captar y procesar los datos que grecogen mis sensores."},
{"composition_05_02", "Mientras que el de mi izquierda está dedicado a las tareas de manipulación y locomoción. Es el ordenador que planifica y da vida a cada uno de mis movimientos."},
{"composition_05_03", "El ordenador que está situado justo en la parte superior se emplea para el procesamiento de visión. De esta forma, cada ordenador se dedica a procesar una parte de la tarea que voy a grealizar."},
{"composition_06", "Tanto el ordenador de manipulación como el de locomoción están conectados a una gred de comunicación yamada can bus, que envía todas las señales de movimiento a cada uno de mis motores."},
{"composition_07", "También poseo sensores de movimiento, inerciales y de fuerza par que me permiten estimar el peso y la presión ejercida en mis articulaciones. Estos sensores permiten por ejemplo que pueda mantenerme en equilibrio mientras ando o estoy de pie."},
{"purpose_01", "Todos los componentes que conforman todo lo que soy, así como los programas que me permiten grealizar todas estas tareas, han sido desagroyados por profesores y estudiantes de esta universidad. La misión principal es poder descubrir y avanzar juntos en el campo de la grobótica."},
{"purpose_02", "Por ahora, tan solo soy un prototipo dedicado a la investigación, por lo que no puedo ser vendido en ninguna tienda. Además, mi precio sería demasiado caro para ser comprado."},
{"ending_01", "Aquí termina mi presentación. Espero que os haya gustado y si queréis, podéis haceros una foto conmigo."},
const std::array sentenceLabels = {
"presentation_01",
"presentation_02",
"composition_01",
"composition_02",
"composition_03",
"composition_04",
"composition_05_01",
"composition_05_02",
"composition_05_03",
"composition_06",
"composition_07",
"purpose_01",
"purpose_02",
"ending_01",
};
}

constexpr auto DEFAULT_PREFIX = "/dialogueManager";
constexpr auto DEFAULT_LANGUAGE = "spanish";
constexpr auto DEFAULT_BACKEND = "espeak";

bool DialogueManager::configure(yarp::os::ResourceFinder & rf)
{
auto language = rf.check("language", yarp::os::Value(DEFAULT_LANGUAGE), "language to be used").asString();
auto backend = rf.check("backend", yarp::os::Value(DEFAULT_BACKEND), "TTS backend").asString();

if (rf.check("help"))
{
yInfo("DialogueManager options:");
yInfo("\t--help (this help)\t--from [file.ini]\t--context [path]");
yInfo("\t--language: %s [%s]", language.c_str(), DEFAULT_LANGUAGE);
yInfo("\t--backend: %s [%s]", backend.c_str(), DEFAULT_BACKEND);
return false;
}

if (!speechPort.open(std::string(DEFAULT_PREFIX) + "/tts/rpc:c"))
yarp::os::Property config;
auto path = rf.findFileByName(language + ".ini");

if (!config.fromConfigFile(path)) {
yError() << "Unable to open configuration file for language" << language;
return false;
}

const auto & group = config.findGroup(backend);

if (group.isNull())
{
yError() << "Unable to open RPC TTS port" << speechPort.getName();
yError() << "Backend" << backend << "for language" << language << "not found";
return false;
}

if (!motionPort.open(std::string(DEFAULT_PREFIX) + "/motion/rpc:c"))
if (!group.check("model"))
{
yError() << "Unable to open RPC motion port" << motionPort.getName();
yError() << "Backend" << backend << "for language" << language << "does not have a voice model";
return false;
}

tts.yarp().attachAsClient(speechPort);
motion.yarp().attachAsClient(motionPort);
voice = group.find("model").asString();

if (language == "english")
for (const auto & label : sentenceLabels)
{
voice = "en_US/m-ailabs_low";
sentences = englishSentences;
const auto & value = group.find(label);

if (!value.isString())
{
yError() << "Backend" << backend << "for language" << language << "does not have sentence" << label;
return false;
}

sentences[label] = value.asString();
}
else if (language == "spanish")

if (!speechPort.open(std::string(DEFAULT_PREFIX) + "/tts/rpc:c"))
{
voice = "mb-es1";
sentences = spanishSentences;
yError() << "Unable to open RPC TTS port" << speechPort.getName();
return false;
}
else

if (!motionPort.open(std::string(DEFAULT_PREFIX) + "/motion/rpc:c"))
{
yError() << "Language not found, please use '--language english' or '--language spanish'";
yError() << "Unable to open RPC motion port" << motionPort.getName();
return false;
}

tts.yarp().attachAsClient(speechPort);
motion.yarp().attachAsClient(motionPort);

return true;
}

Expand Down
3 changes: 3 additions & 0 deletions share/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ yarp_install(FILES applications/ymanager.ini
applications/teo-self-presentation_spanish_sim.xml
applications/teo-self-presentation_spanish.xml
DESTINATION ${TEO-SELF-PRESENTATION_APPLICATIONS_INSTALL_DIR})

yarp_install(DIRECTORY contexts/dialogueManager
DESTINATION ${TEO-SELF-PRESENTATION_CONTEXTS_INSTALL_DIR})
2 changes: 1 addition & 1 deletion share/applications/teo-self-presentation_english.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

<module>
<name>dialogueManager</name>
<parameters>--language english</parameters>
<parameters>--language english --backend espeak</parameters>
<node>localhost</node>
</module>

Expand Down
2 changes: 1 addition & 1 deletion share/applications/teo-self-presentation_english_sim.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<module>
<name>dialogueManager</name>
<parameters>--language english</parameters>
<parameters>--language english --backend espeak</parameters>
<node>localhost</node>
</module>

Expand Down
2 changes: 1 addition & 1 deletion share/applications/teo-self-presentation_spanish.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

<module>
<name>dialogueManager</name>
<parameters>--language spanish</parameters>
<parameters>--language spanish --backend espeak</parameters>
<node>localhost</node>
</module>

Expand Down
2 changes: 1 addition & 1 deletion share/applications/teo-self-presentation_spanish_sim.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<module>
<name>dialogueManager</name>
<parameters>--language spanish</parameters>
<parameters>--language spanish --backend espeak</parameters>
<node>localhost</node>
</module>

Expand Down
33 changes: 33 additions & 0 deletions share/contexts/dialogueManager/english.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[espeak]
model "mb-en1"
presentation_01 "Hi. My name is TEO. I am a humanoid robot designed in the University Carlos Tercero of Madrid. I am 10 years old. My size is 1 70 meters and my weight is 60 kilograms."
presentation_02 "My purpose, is to enable our researchers, to reach new achievements and discoveries, within the robotics area."
composition_01 "I am mainly built, of aluminum, plastic and carbon fiber."
composition_02 "I have 28 degrees, of freedom, that allow me to move freely, being able to do, such human tasks as walking, identifying and manipulating objects, doing household chores, ironing, serving as a waiter, etc."
composition_03 "In my head, I have implemented two cameras, with which, I can detect objects, and human faces. Also, I can detect their distance and depth."
composition_04 "As you can see, I have three computers, in my chest, each dedicated to a different task."
composition_05_01 "The computer on my right, serves me, to capture and process the data collected from my sensors."
composition_05_02 "While, the computer on my left, is dedicated, to the tasks of, manipulation and locomotion. It is the computer that plans and gives life to each of my movements"
composition_05_03 "The computer that is located, just at the top, is dedicated to the processing of vision. In this way, each computer, is dedicated to processing a part of the task that I will perform."
composition_06 "Both of them, the manipulation computer, and the locomotion computer, are connected to a communication network called, can bus, which sends all the motion commands to each of my motors."
composition_07 "I also have movement, inertial, and force sensors, that allow me to detect the weight, and pressure exerted on my joints. These sensors allow, for example, to stay in balance, while walking or standing up."
purpose_01 "All the components that make up everything I am, as well as the programs that allow me to perform all these tasks, have been developed by teachers and students from this university. The main mission is to discover and advance together in the field of robotics."
purpose_02 "For now, I am only a prototype, dedicated to research, so, I can not be sold in any store. Also, my price would be too expensive to be bought."
ending_01 "These, is the end of my presentation. I hope you liked it, and if you want, you can take a picture with me. Nice to meet you."

[piper]
model "en_US-lessac-medium"
presentation_01 "Hi. My name is TEO. I am a humanoid robot designed in the University Carlos Tercero of Madrid. I am 10 years old. My size is 1 70 meters and my weight is 60 kilograms."
presentation_02 "My purpose is to enable our researchers to reach new achievements and discoveries within the robotics area."
composition_01 "I am mainly built of aluminum, plastic and carbon fiber."
composition_02 "I have 28 degrees of freedom that allow me to move freely, being able to do such human tasks as walking, identifying and manipulating objects, doing household chores, ironing, serving as a waiter, etc."
composition_03 "In my head, I have implemented two cameras with which I can detect objects and human faces. Also, I can detect their distance and depth."
composition_04 "As you can see, I have three computers in my chest, each dedicated to a different task."
composition_05_01 "The computer on my right serves me to capture and process the data collected from my sensors."
composition_05_02 "While the computer on my left is dedicated to the tasks of manipulation and locomotion. It is the computer that plans and gives life to each of my movements"
composition_05_03 "The computer that is located just at the top is dedicated to the processing of vision. In this way, each computer, is dedicated to processing a part of the task that I will perform."
composition_06 "Both of them, the manipulation computer and the locomotion computer, are connected to a communication network called can bus, which sends all the motion commands to each of my motors."
composition_07 "I also have movement, inertial, and force sensors that allow me to detect the weight and pressure exerted on my joints. These sensors allow, for example, to stay in balance while walking or standing up."
purpose_01 "All the components that make up everything I am, as well as the programs that allow me to perform all these tasks, have been developed by teachers and students from this university. The main mission is to discover and advance together in the field of robotics."
purpose_02 "For now, I am only a prototype dedicated to research, so I can not be sold in any store. Also, my price would be too expensive to be bought."
ending_01 "This is the end of my presentation. I hope you liked it, and if you want, you can take a picture with me. Nice to meet you."
Loading

0 comments on commit 53488e1

Please sign in to comment.