基于DragonBoard 410c的家庭智能环保卫士——(5)获取kobuki位置信息
来源:互联网 发布:淘宝有没有hm旗舰店 编辑:程序博客网 时间:2024/05/04 02:53
前面已经对基本方案和相关的算法进行了简单介绍,本期blog,将教大家如何快速的获取kobuki机器人的位置信息,由于之前没有研究过ROS,因此,在使用kobuki的时候,只是需要使用kobuki机器人底盘的功能,能够实现对机器人的控制和获取位置信息即可,如果大家想详细的了解kobuki机器人和ROS操作系统,可以到其官网上查询相关资料,在本期blog中将不进行讨论,只是获取我们需要的信息即可。
在http://blog.csdn.net/andymfc/article/details/56671951 blog中已经教大家如何快速的实现对kobuki机器人进行简单的控制,后续也介绍了一种利用kobuki机器人驱动自带的按键控制机器人demo程序来模拟按键控制机器人,这里我们进一步利用该demo来教大家如何通过运行该demo来实时获取机器人的位置信息。
这个demo在运行的过程中会在终端输出kobuki机器人的位置信息,这里我们就可以利用管道重定向将程序输出从终端重定向到我们写的getLocationLocal.py程序中,然后在该程序中获取位置信息,具体代码如下:
#coding=utf-8
import time
import sys
from locationDB import locationDB
maxA=3.2
minA=-3.2
class getRobotLocation:
def __init__(self):
self.currentLocation=""
self.currentX=0.0
self.currentY=0.0
self.currentA=0.0
self.locReport=""
self.flag=0
def startGetThread(self):
print("start get Thread")
while 1:
self.locReport=sys.stdin.readline()
print(self.locReport)
if self.locReport=="current pose: [0, 0, 0]\n":
self.flag=1
if self.flag==1:
self.currentLocation=(self.locReport[15:-2]).split(', ',2)
print(self.currentLocation[0])
print(self.currentLocation[1])
print(self.currentLocation[2])
self.currentX=float(self.currentLocation[0])
self.currentY=float(self.currentLocation[1])
self.currentA=float(self.currentLocation[2])
if self.currentA>0:
self.currentA=self.currentA*180/3.1415926
else:
self.currentA=360+self.currentA*180/3.1415926
print(self.currentLocation)
print(type(self.currentLocation))
LDB=locationDB("./locationDB.db")
LDB.updateCurrentLocation(self.currentX,self.currentY,self.currentA)
def getCurrentLocation(self):
time.sleep(1)
self.currentLocation=sys.stdin.readline()
return self.currentLocation
if __name__ == '__main__':
robotLocation=getRobotLocation()
location=robotLocation.startGetThread()
#print(location)
同时在上述代码中个,还讲位置信息保存到数据库中,数据库是基于sqlite3 数据库构建的数据库,下面是数据库脚本代码:
#coding=utf-8
import sqlite3
class locationDB:
def __init__(self,dbPath):
self.DB=sqlite3.connect(dbPath)
self.cu=self.DB.cursor()
self.DB.execute("")
self.initTable()
def initTable(self):
try:
#create pushInfo table
self.DB.execute("create table locationInfo(infoID integer,currentX float,currentY float,currentA float)")
self.DB.execute("insert into locationInfo values(0,0.0,0.0,0.0)")
self.DB.commit()
print("creat current location info successful")
except:
print("table is already create")
def getCurrentLocation(self):
querySQL="select currentX ,currentY,currentA from locationInfo where infoID==0"
self.cu.execute(querySQL)
result=self.cu.fetchone()
if result==None:
return None
else:
return (result[0],result[1],result[2])
print(result)
def updateCurrentLocation(self,x,y,a):
format="update locationInfo set currentX=%f ,currentY=%f,currentA=%f where infoID ==0"
values=(x,y,a)
updateSQL=format % values
self.cu.execute(updateSQL)
self.DB.commit()
def __del__(self):
self.DB.commit()
self.DB.close()
最后,在启动kobuki机器人键盘控制demo的过程中编写了一个脚本,以便于直接启动demo,脚本代码如下:
#!/bin/bash
export LD_LIBRARY_PATH=/home/linaro/work/kobuik_core/install/lib
/home/linaro/work/kobuik_core/install/lib/kobuki_driver/simple_keyop
#python ./test.py
最后我们将三个代码分别保存为getLocationLocal.py、locationDB.py、startKobuki.sh 三个脚本文件中
最后只需要执行命令 ./startKobuki | python getLocationLocal.py 命令就可以启动获取机器人位置程序,并实时的将位置信息保存到数据库中。
获取结果如下:
- 基于DragonBoard 410c的家庭智能环保卫士——(5)获取kobuki位置信息
- 基于DragonBoard 410c的家庭智能环保卫士——(6)kobuki位置信息传输及显示
- 基于DragonBoard 410c的家庭智能环保卫士——(7)室内栅格地图位置更新
- 基于DragonBoard 410c的家庭智能环保卫士——(11)室内栅格地图位置更新Python实现
- 基于Dragonboard 410c的家庭智能环保卫士——(2)方案设计
- 基于Dragonboard 410c的家庭智能环保卫士——(3)室内路径规划
- 基于DragonBoard 410c的家庭智能环保卫士——(8)室内栅格定位
- 基于DragonBoard 410c的家庭智能环保卫士——(9)数据库设计
- 基于DragonBoard 410c的家庭智能环保卫士——(12)环境数据融合
- 基于DragonBoard 410c的家庭智能环保卫士——(13)融合多数据处理的运动控制
- 基于DragonBoard 410c的家庭智能环保卫士——(4)A*路径搜索算法
- 基于DragonBoard 410c的家庭智能环保卫士——(10)数据库python代码实现
- 基于Dragonbaord 410c的家庭智能环保卫士——(1)预研
- 基于dragonboard 410c的kobuki机器人简单控制——驱动安装
- 基于dragonboard 410c的kobuki机器人控制——远程控制
- 基于dragonboard410c 家庭智能环保卫士之PM2.5模块代码分析
- 基于dragonboard410c 家庭智能环保卫士之PM2.5模块简介
- 基于dragonboard 410c的智能魔镜设计(5)——基于人脸的用户身份识别
- 光源
- MyEclipse 常用快捷键总结
- linux tar.gz zip 解压缩 压缩命令
- tensorflow学习笔记十三:TF官方教程学习 TensorFlow Mechanics 101
- VS2012发布项目到服务器
- 基于DragonBoard 410c的家庭智能环保卫士——(5)获取kobuki位置信息
- freemarker教程
- 免费ARP
- Java1.7通过collections类的sort方法对ArrayList进行排序无效的解决办法。
- Unity3D 使用Protobuf ProtobufHelper
- cadence 网络标号和off page
- 解析xml(使用Dom4j)--简单高效
- echart同一个页面,多个图表宽高自适应
- JavaScript继承实现