-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
260 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
set(appname r1Obr-orchestrator) | ||
|
||
file(GLOB conf ${CMAKE_CURRENT_SOURCE_DIR}/conf/*.ini) | ||
file(GLOB templates ${CMAKE_CURRENT_SOURCE_DIR}/scripts/*.template) | ||
file(GLOB apps ${CMAKE_CURRENT_SOURCE_DIR}/scripts/*.xml) | ||
file(GLOB conf ${CMAKE_CURRENT_SOURCE_DIR}/conf/*.ini) | ||
file(GLOB robotInterface ${CMAKE_CURRENT_SOURCE_DIR}/conf/robotInterface/*.xml) | ||
file(GLOB templates ${CMAKE_CURRENT_SOURCE_DIR}/scripts/*.template) | ||
file(GLOB apps ${CMAKE_CURRENT_SOURCE_DIR}/scripts/*.xml) | ||
|
||
yarp_install(FILES ${conf} DESTINATION ${${PROJECT_NAME}_CONTEXTS_INSTALL_DIR}/${appname}) | ||
yarp_install(FILES ${apps} DESTINATION ${${PROJECT_NAME}_APPLICATIONS_INSTALL_DIR}) | ||
yarp_install(FILES ${scripts} DESTINATION ${${PROJECT_NAME}_APPLICATIONS_TEMPLATES_INSTALL_DIR}) | ||
|
||
yarp_install(FILES ${robotInterface} DESTINATION ${${PROJECT_NAME}_CONTEXTS_INSTALL_DIR}/${appname}/robotInterface) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
config robotInterface/chatBot_nwc_test.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 6 additions & 1 deletion
7
app/r1Obr-orchestrator/conf/r1Obr-orchestrator_R1_noContinuousSearch.ini
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
app/r1Obr-orchestrator/conf/robotInterface/chatBot_nwc_test.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT) | ||
SPDX-License-Identifier: BSD-3-Clause | ||
--> | ||
<!DOCTYPE robot PUBLIC "-//YARP//DTD yarprobotinterface 3.0//EN" "http://www.yarp.it/DTD/yarprobotinterfaceV3.0.dtd"> | ||
<robot name="chatBotTest" build="2" portprefix="" xmlns:xi="http://www.w3.org/2001/XInclude"> | ||
<devices> | ||
<device name="chatBotNwc" type="chatBot_nwc_yarp"> | ||
<param extern-name="test_local" name="local"> | ||
/test/chatBot | ||
</param> | ||
<param extern-name="test_remote" name="remote"> | ||
/chatBot_nws/rpc | ||
</param> | ||
</device> | ||
</devices> | ||
</robot> |
18 changes: 18 additions & 0 deletions
18
app/r1Obr-orchestrator/conf/robotInterface/speechSynthesizer_nwc_test.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT) | ||
SPDX-License-Identifier: BSD-3-Clause | ||
--> | ||
<!DOCTYPE robot PUBLIC "-//YARP//DTD yarprobotinterface 3.0//EN" "http://www.yarp.it/DTD/yarprobotinterfaceV3.0.dtd"> | ||
<robot name="speechSynthesizerTest" build="2" portprefix="" xmlns:xi="http://www.w3.org/2001/XInclude"> | ||
<devices> | ||
<device name="speechSynthesizerNwc" type="speechSynthesizer_nwc_yarp"> | ||
<param extern-name="test_local" name="local"> | ||
/test/speechSynthesizer | ||
</param> | ||
<param extern-name="test_remote" name="remote"> | ||
/speechSynthesizer_nws_yarp | ||
</param> | ||
</device> | ||
</devices> | ||
</robot> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
config robotInterface/chatBot_nwc.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
/* | ||
* Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT) | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2.1 of the License, or (at your option) any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this library; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
*/ | ||
|
||
#include "inputManager.h" | ||
|
||
YARP_LOG_COMPONENT(INPUT_MANAGER, "r1_obr.orchestrator.inputManager") | ||
|
||
|
||
InputManager::InputManager(double _period, yarp::os::ResourceFinder &rf) | ||
: PeriodicThread(_period), m_rf(rf) {} | ||
|
||
|
||
// ****************************************************** // | ||
bool InputManager::threadInit() | ||
{ | ||
// Defaults | ||
string voiceCommandPortName = "/r1Obr-orchestrator/voice_command:i"; | ||
string inputCommandPortName = "/r1Obr-orchestrator/input_command:i"; | ||
string inputManagerRPCPortName = "/r1Obr-orchestrator/inputManager:rpc"; | ||
string device_chatBot_nwc = "chatBot_nwc_yarp"; | ||
string local_chatBot_nwc = "/r1Obr-orchestrator/chatBot"; | ||
string remote_chatBot_nwc = "/chatBot_nws"; | ||
string language_chatbot = "auto"; | ||
|
||
// ------------------ out ------------------ // | ||
if(!m_inputManagerRPCPort.open(inputManagerRPCPortName)) | ||
{ | ||
yCError(INPUT_MANAGER, "Unable to open input manager RPC port"); | ||
return false; | ||
} | ||
|
||
// ------------------ in ------------------ // | ||
if(!m_rf.check("INPUT_MANAGER")) | ||
{ | ||
yCWarning(INPUT_MANAGER,"INPUT_MANAGER section missing in ini file. Using the default values"); | ||
} | ||
|
||
Searchable& inputs_config = m_rf.findGroup("INPUT_MANAGER"); | ||
if(inputs_config.check("voice_command_port")) {voiceCommandPortName = inputs_config.find("voice_command_port").asString();} | ||
if(inputs_config.check("input_command_port")) {inputCommandPortName = inputs_config.find("input_command_port").asString();} | ||
|
||
|
||
// Voice Command Port | ||
if (!m_voiceCommandPort.open(voiceCommandPortName)) | ||
{ | ||
yCError(INPUT_MANAGER, "Unable to open voice command port"); | ||
return false; | ||
} | ||
m_voiceCommandPort.useCallback(*this); | ||
|
||
// Other Input Port | ||
if (!m_inputCommandPort.open(inputCommandPortName)) | ||
{ | ||
yCError(INPUT_MANAGER, "Unable to open input command port"); | ||
return false; | ||
} | ||
|
||
// iChatBot | ||
m_chatBot_active = inputs_config.check("chatbot_active") ? (inputs_config.find("chatbot_active").asString() == "true") : false; | ||
|
||
if(m_chatBot_active) | ||
{ | ||
Property chatBotProp; | ||
chatBotProp.put("device", inputs_config.check("device", Value(device_chatBot_nwc))); | ||
chatBotProp.put("local", inputs_config.check("local", Value(local_chatBot_nwc))); | ||
chatBotProp.put("remote", inputs_config.check("remote", Value(remote_chatBot_nwc))); | ||
m_PolyCB.open(chatBotProp); | ||
if(!m_PolyCB.isValid()) | ||
{ | ||
yCWarning(INPUT_MANAGER,"Error opening PolyDriver check parameters. Using the default values"); | ||
} | ||
m_PolyCB.view(m_iChatBot); | ||
if(!m_iChatBot){ | ||
yCError(INPUT_MANAGER,"Error opening IChatBot interface. Device not available"); | ||
return false; | ||
} | ||
|
||
if(inputs_config.check("language")) language_chatbot = inputs_config.find("language").asString(); | ||
m_iChatBot->setLanguage(language_chatbot); | ||
} | ||
|
||
|
||
|
||
return true; | ||
} | ||
|
||
|
||
// ****************************************************** // | ||
void InputManager::threadRelease() | ||
{ | ||
if(!m_voiceCommandPort.isClosed()) | ||
m_voiceCommandPort.close(); | ||
|
||
if(!m_inputCommandPort.isClosed()) | ||
m_inputCommandPort.close(); | ||
|
||
if (m_inputManagerRPCPort.asPort().isOpen()) | ||
m_inputManagerRPCPort.close(); | ||
|
||
if(m_PolyCB.isValid()) | ||
m_PolyCB.close(); | ||
|
||
yCInfo(INPUT_MANAGER, "Input Manager thread released"); | ||
} | ||
|
||
|
||
// ****************************************************** // | ||
void InputManager::run() | ||
{ | ||
Bottle* inputCommand = m_inputCommandPort.read(false); | ||
if(inputCommand != nullptr) | ||
{ | ||
writeToRPC(*inputCommand); | ||
} | ||
} | ||
|
||
|
||
// ****************************************************** // | ||
void InputManager::onRead(Bottle& b) | ||
{ | ||
string b_str = b.toString(); | ||
yCInfo(INPUT_MANAGER,"Received: %s",b_str.c_str()); | ||
|
||
string msg; | ||
m_iChatBot->interact(b_str, msg); | ||
yCInfo(INPUT_MANAGER,"ChatBot replied: %s",msg.c_str()); | ||
|
||
Bottle msg_btl; | ||
msg_btl.fromString(msg); | ||
writeToRPC(msg_btl); | ||
} | ||
|
||
|
||
// ****************************************************** // | ||
void InputManager::writeToRPC(Bottle& req) | ||
{ | ||
Bottle _rep_; | ||
m_inputManagerRPCPort.write(req,_rep_); | ||
|
||
yCInfo(INPUT_MANAGER, "Replied from orchestrator: %s", _rep_.toString().c_str() ); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.