遠端訪問nao機器人和遠端執行led程式總結
環境:虛擬機器VMware® Workstation 15 Pro下的ubuntu-18.04.3-desktop-amd64
1.安裝好qibuild和C++環境
首先按照官方教程安裝好qibuild和C++環境(注意是在Linux環境下,別看走眼):https://developer.softbankrobotics.com/nao6/naoqi-developer-guide/sdks/c-sdk/c-sdk-installation-guide#cpp-install-guide
qibuild是用來編譯C++程式碼的從而生成可執行檔案
2.構建程式碼並編譯生成可執行檔案
可以在my_worktree下面生成另外一個資料夾,和第一步裡面的內容一樣,有CMakeLists.txt,qiproject.xml,還有用以下qibuild命令生成的build-myconfig資料夾,具體看下圖,也就是上面官網連結裡的內容
qibuild configure --release
接著,根據官方連結的內容:https://developer.softbankrobotics.com/nao-naoqi-2-1/naoqi-developer-guide/programming/c-sdk/c-examples/control-leds,生成一個main.cpp檔案,內容如下:
#include <iostream> #include <alerror/alerror.h> #include <alproxies/alledsproxy.h> int main(int argc, char* argv[]) { if(argc != 2) { std::cerr << "Wrong number of arguments!" << std::endl; std::cerr << "Usage: movehead NAO_IP" << std::endl; exit(2); } try { /** Create a ALLedsProxy to call the methods to deal with NAO's leds. * Arguments for the constructor are: * - IP adress of the robot * - port on which NAOqi is listening, by default 9559*/ AL::ALLedsProxy leds(argv[1], 9559); /** Set the duration of the animation. */ float duration = 3.0f; /** Play a green / yellow / red animation on all of NAO's leds. */ leds.rasta(duration); } catch (const AL::ALError& e) { std::cerr << "Caught exception: " << e.what() << std::endl; exit(1); } exit(0); }
還有CMakeLists.txt檔案的內容需要修改,全部換為以下內容(也可以把原先的內容註釋掉):
cmake_minimum_required(VERSION 2.6.4 FATAL_ERROR) # Give a name to the project. project(ledsexample) # This include enable you to use qibuild CMake framework find_package(qibuild) # Create an executable named ledsexample, # with the source file : ledsexample.cpp qi_create_bin(ledsexample ledsexample.cpp) # Tell CMake that movehead depends on ALCOMMON and ALPROXIES. # This will set the libraries to link movehead with, # the include paths, and so on qi_use_lib(ledsexample ALCOMMON ALPROXIES)
這時候以上內容沒有報錯的情況下,使用命令編譯生成可執行檔案:
qibuild make
得到以下內容,由於內容過多,就只放出最後成功生成可執行檔案ledsexample的結果:
3.修改網路IP並遠端訪問nao機器人
由於環境是虛擬機器下的Ubuntu18.04.3,比較新,官方也修改了對應網路配置的檔案。這方面許多人都寫的很好,我就直接引用我成功執行的一個連結:https://blog.csdn.net/u014454538/article/details/88646689?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.nonecase&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.nonecase
這裡可能需要點網路知識,Ubuntu的IP需要和nao機器人的IP在同一個網段,比如nao機器人的IP為192.168.1.6,則Ubuntu的IP需要改為192.168.1.66,反正最後一個點後面的數字需要不一樣,但也不能為1或255。
這裡我設定的IP是192.168.1.36/24,根據上面的連結,需要加斜槓 / , 不加的話會報錯。閘道器和DNS伺服器我設定和主機一樣,這裡可以自己開啟主機windows下的命令提示符然後敲ipconfig檢視 或者 開啟設定下的網路狀態檢視相關資訊。
還有一點就是虛擬機器的設定,如下:
修改好了之後我們可以先用 ssh 連線訪問一下nao機器人看看通不通,執行以下命令:
ssh nao@192.168.1.101
其中,192.168.1.101是機器人的IP,成功接入如下:
最後,執行可執行檔案:
接著就可以看到nao的眼睛顏色變成五顏六色並持續一段時間!