NAO机器人学习小计
NAO APIs
nao的接口全部以AL開頭,全部繼承自ALModule,它被包含在<alcommon/almodule.h>中。
下面是ALModule的主要methods。
ALModule APIs
namespace : AL
#include <alcommon/almodule.h>任務(wù)調(diào)度
ALModule::isRunning()
bool ALModule::isRunning(const int& id); 確定被一個(gè)‘post’創(chuàng)建的方法是否還在運(yùn)行。(注:post可能類似于一個(gè)線程池管理員,方法的編號(hào)可能類似于線程號(hào))。params: id - 被post所返回的函數(shù)的編號(hào) return: true表示該方法正在被執(zhí)行,false表示該方法沒有被執(zhí)行。ALModule::wait()
bool ALModule::wait(const int& id, const int& timeour); 等待編號(hào)為id的方法執(zhí)行完畢。params: id - 被post所返回的函數(shù)的編號(hào)timeout - ms為單位,表示 return: true表示該方法正在被執(zhí)行,false表示該方法沒有被執(zhí)行。ALModule::stop()
void ALModule::stop(const int& id); 根據(jù)id停止相應(yīng)方法。比較提倡模塊開發(fā)人員實(shí)現(xiàn)這個(gè)接口,當(dāng)模塊內(nèi)包含長(zhǎng)時(shí)間執(zhí)行的方法,而又希望允許用戶打斷。params: id - 被post返回的方法的編號(hào) return:ALModule::exit()
void ALModule::exit(); 將這個(gè)模塊從父經(jīng)紀(jì)人(parent broker)中注銷。一旦這個(gè)方法被調(diào)用,這個(gè)模塊將不再可用。開發(fā)人員應(yīng)該在希望執(zhí)行徹底的關(guān)機(jī)任務(wù)時(shí)重寫這個(gè)方法。——warning: 不建議在核心模塊(例如 ALMemory 或者 ALMotion)中存在別的模塊或者方法正在調(diào)用它們時(shí)使用。
Bound Methods - Introspection
(↑不太理解,字面翻譯是:綁定的方法-反思)
ALModule::getBrokerName()
std::string ALModule::getBrokerName(); 獲取父經(jīng)紀(jì)人的名稱return: 父經(jīng)紀(jì)人的名稱。ALModule::getMethodList()
std::vectore<std::string> ALModule::getMethodList(); 獲取當(dāng)前模塊的方法名稱列表。return: 包含方法名稱的向量。ALModule::getMethodHelp()
AL::ALValue ALModule::getMethodHelp(const std::string& methodName); 獲取一個(gè)方法的描述文檔。params: methodName - 方法的名稱 return: 一個(gè)包含了方法的描述內(nèi)容的結(jié)構(gòu)體注: AL::ALValue [std::string methodName, [ parameter, ... ]std::string returnName,std::string returnDescription ]parameter: [std::string parameterName,std::string parameterDescription ]ALModule::getModuleHelp()
AL::ALValue ALModule::getModuleHelp(); 獲取當(dāng)前模塊的描述。return: 一個(gè)包含模塊描述的結(jié)構(gòu)體。注: AL::ALValue [std::string moduleDescription,[ moduleExample, ... ] ]moduleExample: [std::string language,std::string example ]ALModule::getUsage()
std::string ALModule::stop(const std::string& methodName); 根據(jù)函數(shù)名稱返回該函數(shù)的用法。params: methodName - 函數(shù)名稱。 return: 總結(jié)了該函數(shù)用法的字符串。ALModule::ping()
bool ALModule::ping(); 單純?yōu)榱藴y(cè)試連接的ping。永遠(yuǎn)返回truereturn: trueALModule::version()
std::string ALModule::version(); 返回模塊的版本return: 模塊的版本信息字符串。以上接口將作為公共接口存在于所有模塊中。
由于我們的項(xiàng)目以通信為主,因此我們優(yōu)先關(guān)注通信模塊ALConnectionManagerProxy。
概覽:
ALConnectionManager提供管理網(wǎng)絡(luò)連接的方法。它包含了一些允許你連接或配置一個(gè)網(wǎng)絡(luò)的命令,并且也可以獲取網(wǎng)絡(luò)的屬性或者創(chuàng)建一個(gè)網(wǎng)絡(luò)。
ALConnectionManager支持的網(wǎng)絡(luò)包括:以太網(wǎng)、無線網(wǎng)和藍(lán)牙。
主要的特性包括:
列舉出所有可用的網(wǎng)路服務(wù)。
連接到一個(gè)網(wǎng)絡(luò)服務(wù)。
創(chuàng)建一個(gè)網(wǎng)絡(luò)服務(wù)(包括WiFi熱點(diǎn)以及藍(lán)牙個(gè)人局域網(wǎng)(Bluetooth PAN))。
列舉可用的網(wǎng)絡(luò)技術(shù)(WiFi、藍(lán)牙、以太網(wǎng))。
對(duì)一個(gè)網(wǎng)絡(luò)服務(wù)進(jìn)行配置。
這個(gè)模塊提供網(wǎng)絡(luò)服務(wù)的一些有用的信息,比如WiFi連接的強(qiáng)度、現(xiàn)在的狀態(tài)、以及安全要求。
這個(gè)模塊通過事件機(jī)制來通知網(wǎng)絡(luò)的變化。
性能和約束:
ALConnectionManager只在機(jī)器人端可用。
暫時(shí)不支持WPA安全加密。
搜索可用wifi熱點(diǎn)的功能在熱點(diǎn)模式下不可用。
ALConnectionManager不處理藍(lán)牙設(shè)備的配對(duì)過程。
ALConnectionManager APIs
namespace : AL
#include <alproxies/alconnectionmanagerproxy.h>連接管理模塊繼承自ALModule API。它也有自有的下列方法:
ALConnectionManagerProxy::state() ALConnectionManagerProxy::services() ALConnectionManagerProxy::technologies() ALConnectionManagerProxy::service() ALConnectionManagerProxy::connect() ALConnectionManagerProxy::disconnect() ALConnectionManagerProxy::forget() ALConnectionManagerProxy::setServiceConfiguration() ALConnectionManagerProxy::setServiceInput() ALConnectionManagerProxy::scan() ALConnectionManagerProxy::enableTethering() ALConnectionManagerProxy::disableTethering() ALConnectionManagerProxy::getTetheringEnable() ALConnectionManagerProxy::tetheringName() ALConnectionManagerProxy::tetheringPassphrase() ALConnectionManagerProxy::countries() ALConnectionManagerProxy::country() ALConnectionManagerProxy::setCountry() ALConnectionManagerProxy::interfaces()ALConnectionManagerProxy::state()
std::string ALConnectionManagerProxy::state(); 返回網(wǎng)絡(luò)連接的狀態(tài)(全局)。可能的值包括: · "online" - 當(dāng)有互聯(lián)網(wǎng)連接可用時(shí)。 · "ready" - 至少有一個(gè)設(shè)備被成功地連接 · "offline" - 目前沒有設(shè)備連接到naoreturn: 全局的連接管理器狀態(tài)。示例代碼:
#python 2.7from naoqi import ALProxyNAO_IP = "127.0.0.1"alConnectionManager = ALProxy("ALConnectionManager", NAO_IP, 9559)print "network state: " + alConnectionManager.state()ALConnectionManagerProxy::scan()
std::string ALConnectionManagerProxy::state(); 搜索臨近的網(wǎng)絡(luò)服務(wù)(包括所有可用的網(wǎng)絡(luò)技術(shù))。可用服務(wù)的列表會(huì)被刷新,并在稍后被顯示,這很有用。ALConnectionManagerProxy::services()
AL::ALValue ALConnectionManagerProxy::services(); 返回包含所有可用網(wǎng)絡(luò)服務(wù)的名稱以及屬性的列表。在此之前調(diào)用`ALConnectionManagerProxy::scan()`會(huì)更有用。return: 一個(gè)ALValueNetworkInfo的數(shù)組。示例代碼:
#列出所有可用的網(wǎng)絡(luò)服務(wù)#coding=utf-8from naoqi import ALProxyNAO_IP = "127.0.0.1"alconnman = ALProxy("ALConnectionManager", NAO_IP, 9559)#Scanning is required to update the services list alconnman.scan() services = alconnman.services()for service in services:network = dict(service)if network["Name"] == "":print "{hidden} " + network["ServiceId"]else:print network["Name"] + " " + network["ServiceId"]ALConnectionManagerProxy::service()
AL::ALValue ALConnectionManagerProxy::service(const std::string& serviceId); 返回一個(gè)指定的服務(wù)名稱的服務(wù)的網(wǎng)絡(luò)屬性。網(wǎng)絡(luò)信息NetworkInfo通過ALValue來表示。params: serviceId - 希望獲得屬性的網(wǎng)絡(luò)服務(wù)名稱 return: 指定的服務(wù)名稱網(wǎng)絡(luò)的屬性。 throws: 該網(wǎng)絡(luò)服務(wù)不可用時(shí),拋出ALError示例代碼:
#獲得一個(gè)網(wǎng)絡(luò)服務(wù)的屬性 #coding=utf-8 from naoqi import ALProxy import sysNAO_IP = "127.0.0.1"if len(sys.argv) != 2:print sys.argv[0] + " <serviceId>"sys.exit(1)alconnman = ALProxy("ALConnectionManager", NAO_IP, 9559)try:service = alconnman.service(sys.argv[1]) except Exception as e:print e.what()sys.exit(1)service = dict(service) print "Network Service: " + sys.argv[1] for key, value in service.iteritems():print "\t" + key + ": " + str(value)ALConnectionManagerProxy::connect()
void ALConnectionManagerProxy::connect(const std::string& serviceId); 連接到一個(gè)網(wǎng)絡(luò)服務(wù)。params: serviceId - 將要連接到的網(wǎng)絡(luò)的名稱 throws: 該網(wǎng)絡(luò)服務(wù)不可用時(shí),拋出ALError注意:
如果在連接到這個(gè)網(wǎng)絡(luò)時(shí)需要?jiǎng)e的信息(比如需要登錄密碼,或者登錄隱藏網(wǎng)絡(luò)需要網(wǎng)絡(luò)名稱時(shí)),將會(huì)產(chǎn)生一個(gè)event。
See also
NetworkServiceInputRequired(), NetworkConnectStatus()
示例代碼:
#連接到一個(gè)網(wǎng)絡(luò) from naoqi import ALProxy import sysNAO_IP = "127.0.0.1"if len(sys.argv) != 2:print sys.argv[0] + " <serviceId>"sys.exit(1)alconnman = ALProxy("ALConnectionManager", NAO_IP, 9559)try:alconnman.connect(sys.argv[1]) except Exception as e:print e.what()sys.exit(1)ALConnectionManagerProxy::disconnect()
void ALConnectionManagerProxy::disconnect(const std::string& serviceId); 斷開到一個(gè)網(wǎng)絡(luò)服務(wù)的連接。params: serviceId - 將要斷開的網(wǎng)絡(luò)的名稱 throws: 該網(wǎng)絡(luò)服務(wù)不可用時(shí),拋出ALError示例代碼:
#斷開一個(gè)網(wǎng)絡(luò)連接 from naoqi import ALProxy import sysNAO_IP = "127.0.0.1"if len(sys.argv) != 2:print sys.argv[0] + " <serviceId>"sys.exit(1)alconnman = ALProxy("ALConnectionManager", NAO_IP, 9559)try:alconnman.disconnect(sys.argv[1]) except Exception as e:print e.what()sys.exit(1)ALConnectionManagerProxy::disconnect()
void ALConnectionManagerProxy::forget(const std::string& serviceId); 忘記一個(gè)偏好網(wǎng)絡(luò)。需要獲得網(wǎng)絡(luò)服務(wù)的名稱來忘記相關(guān)聯(lián)的信息。這還會(huì)使得這個(gè)網(wǎng)絡(luò)不再是偏好網(wǎng)絡(luò),并且不會(huì)被自動(dòng)連接。params: serviceId - 將要忘記的網(wǎng)絡(luò)的名稱 throws: 該網(wǎng)絡(luò)服務(wù)不可用時(shí),拋出ALError示例代碼:
#忘記一個(gè)網(wǎng)絡(luò) from naoqi import ALProxy import sysNAO_IP = "127.0.0.1"if len(sys.argv) != 2:print sys.argv[0] + " <serviceId>"sys.exit(1)alconnman = ALProxy("ALConnectionManager", NAO_IP, 9559)try:service = alconnman.forget(sys.argv[1]) except Exception as e:print e.what()sys.exit(1)ALConnectionManagerProxy::setServiceConfiguration()
void ALConnectionManagerProxy::setServiceConfiguration(const AL::ALValue& configuration) 給定需要應(yīng)用的靜態(tài)網(wǎng)絡(luò)配置。以下屬性在靜態(tài)配置中是可用的: · 是否自動(dòng)連接 · 域名 · 域名服務(wù)器 · IPv4 · IPv6(實(shí)驗(yàn)性的)params: configuration - 一個(gè)將要被應(yīng)用網(wǎng)絡(luò)配置的包含了NetWorkInfo的ALValue。 throws: 當(dāng)網(wǎng)絡(luò)服務(wù)不可用的時(shí)候拋出ALError當(dāng)配置信息不合法時(shí)拋出ALError當(dāng)網(wǎng)絡(luò)服務(wù)不需要配置時(shí)拋出ALErrorSee also
NetworkInfo
(未完)
ALRobotPosture模塊
概覽
暫時(shí)現(xiàn)在看看motion部分的模塊。ALRobotPosture模塊允許用戶將機(jī)器人定位到已經(jīng)定義好的姿勢(shì)。
可以選擇使用ALRobotPostureProxy::goToPosture()或者ALRobotPosture::applyPosture.
如果想要?jiǎng)?chuàng)建一個(gè)自動(dòng)化的應(yīng)用,務(wù)必選擇ALRobotPostureProxy::goToPosture().
如果你僅僅希望在操控機(jī)器人時(shí),迅速達(dá)到某個(gè)姿勢(shì),可以選擇ALRobotPostureProxy::applyPosture,(你必須要協(xié)助機(jī)器人)。
這如何工作?
機(jī)器人會(huì)偵測(cè)到現(xiàn)在它正處于那種姿勢(shì),然后計(jì)算出一個(gè)路徑,使得它可以從現(xiàn)在的姿勢(shì)變換到目標(biāo)姿勢(shì),然后執(zhí)行這條線路。
可能允許選擇姿勢(shì)變換的速度。
定義
姿勢(shì)
機(jī)器人的姿勢(shì)是一個(gè)獨(dú)特的,對(duì)他的關(guān)節(jié)和慣性傳感器的配置。
由于姿勢(shì)是由一組實(shí)數(shù)(比如說float)定義的,所以會(huì)有無數(shù)種姿勢(shì)。
預(yù)定義的姿勢(shì)
下面是預(yù)定義的姿勢(shì)列表:
蹲伏(Crouch)
仰面躺(LyingBack)
面向下趴著(LyingBelly)
正坐(Sit)
箕踞(SitRelax)
站立(Stand)
預(yù)行走站立(StandInit)
向前看齊(StandZero)
有一些姿勢(shì)(比如Sit或Lying)并不是對(duì)所有機(jī)器人都是可用的。
使用ALRobotPostureProxy::getPostureList()來獲取你的機(jī)器人上可用的預(yù)定義的姿勢(shì)列表。
姿勢(shì)族
由于姿勢(shì)的種類有無數(shù)種,姿勢(shì)被劃分為姿勢(shì)族,以是的姿勢(shì)更加容易理解。
以下是姿勢(shì)族列表:
使用ALRobotPostureProxy::getPostureFamilyList(),就可以知道你的機(jī)器人上有哪些可用的姿勢(shì)族。它一定是下面這個(gè)列表的子集。
| Standing | 機(jī)器人的中心在腳上,并且機(jī)器人的軀干是筆直向上的的。 |
| Sitting | 機(jī)器人的尾部接觸地面,并且軀干是筆直向上的。 |
| SittingOnChair | 機(jī)器人的尾部接觸一個(gè)高約10cm的椅子,并且軀干是筆直向上的。 |
| LyingBelly | 身體平展,并且面向下 |
| LyingBack | 身體平展,并且面向上 |
| LyingLeft | 身體平展,并且面向右側(cè) |
| LyingRight | 身體平展,并且面向左側(cè) |
| Belly | 面向下并且軀干懸空 |
| Back | 面向后并且軀干懸空 |
| Left | 膝蓋跪向左側(cè),并且手部著地 |
| Right | 膝蓋跪向右側(cè),并且手部著地 |
namespace:AL
方法列表
和別的模塊一樣,這個(gè)模塊繼承自ALModule API。它也有自有的下列方法。
class ALRobotPostureProxy:
ALRobotPostureProxy::getPostureList()
ALRobotPostureProxy::getPosture()
ALRobotPostureProxy::goToPosture()
ALRobotPostureProxy::applyPosture()
ALRobotPostureProxy::stopMove()
ALRobotPostureProxy::getPostureFamily()
ALRobotPostureProxy::getPostureFamilyList()
ALRobotPostureProxy::setMaxTryNumber()
事件
PostureFamilyChanged()
PostureChanged()
方法
ALRobotPostureProxy::getPostureList()
std::vector<std::string> ALRobotPostureProxy::getPostureList(); 返回一個(gè)包含所有已經(jīng)定義姿勢(shì)的列表。return: 包含所有已定義姿勢(shì)的向量ALRobotPostureProxy::getPosture()
std::string ALRobotPostureProxy::getPosture() 返回現(xiàn)在的**預(yù)定義姿勢(shì)**名稱。如果現(xiàn)在的姿勢(shì)不是預(yù)定義姿勢(shì),就會(huì)返回"Unknown". return: 一個(gè)包含現(xiàn)在姿勢(shì)的名稱的字符串。ALRobotPostureProxy::goToPoture()
bool ALRobotPostureProxy::gotoPosture(const std::string postureName, const float speed); 讓機(jī)器人變換到預(yù)定義的姿勢(shì)。速度可能是可以調(diào)節(jié)的。這個(gè)變化是“智能的”,它會(huì)從現(xiàn)在已有的開始姿勢(shì),自動(dòng)選擇每一步,以變換到目標(biāo)姿勢(shì)。 這是一個(gè)會(huì)阻塞的函數(shù)調(diào)用。如果希望它不會(huì)阻塞線程,使用post。 params: postureName - 預(yù)定義的姿勢(shì)名稱字符串。speed - 相對(duì)速度,范圍從0.0 - 1.0 return: 一個(gè)布爾值,表明目標(biāo)姿勢(shì)是否正確達(dá)到。ALRobotPostureProxy::applyPosture()
bool ALRobotPostureProxy::applyPosture(const std::string& postureName, const float& speed); 將所有的預(yù)定義姿勢(shì)中提到的關(guān)節(jié)設(shè)置到定義中的狀態(tài)。 在操控機(jī)器人時(shí),使用這個(gè)方法以達(dá)到顯示出動(dòng)作的效果。請(qǐng)將他想象成一條姿勢(shì)變換的捷徑,假設(shè)這是你想要快速達(dá)到某一個(gè)姿勢(shì)。機(jī)器人可能需要使用者的幫助以達(dá)到這個(gè)姿勢(shì)。 這個(gè)方法的效果是立即的,并且其中沒有只能因素在里面。所以在設(shè)置姿勢(shì)時(shí),請(qǐng)小心。比方說,如果機(jī)器人現(xiàn)在正坐著,你調(diào)用了applyPosture("StandInit", 1.0)。這對(duì)于機(jī)器人可能是非常危險(xiǎn)的,如果你不幫助機(jī)器人站起來的話,它就會(huì)跌倒。 如果你想要機(jī)器人獨(dú)立地站起來,調(diào)用goToPosture(). 這是一個(gè)會(huì)阻塞的函數(shù)調(diào)用。如果希望它不會(huì)阻塞線程,使用post。params: postureName - 預(yù)定義的姿勢(shì)名稱字符串。speed - 相對(duì)速度,范圍從0.0 - 1.0 return: 一個(gè)布爾值,表明目標(biāo)姿勢(shì)是否正確達(dá)到。ALRobotPostureProxy::stopMove()
void ALRobotPostureProxy::stopMove(); 停止當(dāng)前的姿勢(shì)插補(bǔ)動(dòng)作。ALRobotPostureProxy::getPostureFamily()
std::string ALRobotPostureProxy::getPostureFamily(); 返回姿勢(shì)族。return: 返回當(dāng)前的姿勢(shì)族名稱。ALRobotPostureProxy::getPostureFamilyList()
std::vector<std::string> ALRobotPostureProxy::getPostureFamilyList(); 返回一個(gè)包含了所有預(yù)定義的姿勢(shì)族名稱的向量。return: 一個(gè)包含了所有預(yù)定義姿勢(shì)族名稱的vector.ALRobotPostureProxy::setMaxTryNumber(const int& maxTryNumber)
void ALRobotPostureProxy::setMaxTryNumber(const int& maxTryNumber); 設(shè)置當(dāng)調(diào)用`ALRobotPostureProxy::goToPosture()`返回失敗之前,最大的嘗試次數(shù)。params: maxTryNumber - 嘗試的次數(shù),默認(rèn)值是3.Event: "PostureFamilyChanged"
callback(std::string eventName, std::string PostureFamily, std::string subscriberIdentifier); 當(dāng)姿勢(shì)族發(fā)生改變時(shí),傳遞出姿勢(shì)族的名稱。 這個(gè)事件的更新頻率大約是一秒鐘。Event: "PostureChanged"
callback(std::string eventName, std::string Posture, std::string subscriberIdentifier): 當(dāng)姿勢(shì)發(fā)生改變時(shí),傳遞出姿勢(shì)的名稱。 這個(gè)事件的更新頻率大約是一秒鐘。總結(jié)
以上是生活随笔為你收集整理的NAO机器人学习小计的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: sys.getsizeof(), 字节之
- 下一篇: ansible基本模块使用