ASU-VPL控制智能小车,安卓手机客户端控制

1.ASU-VPL通过WiFi连接,网络传输遵从的是IP/TCP协议,传输数据通过socket,它与机器人通信通过利用JSON对象,它的数据发送和接收格式:
ROBOT OUTPUT
name: string ( touch ,distance ,sound ,light ,color ,motorEncoder)
id: int value: For touch sensor,value will be an int (0=not pressed and 1=pressed).
For other sensors, value will be a double
{“sensors”: [{“name”:”touch”,”id”:0, “value”:0},{“name”:”distance”, “id”:0, “value”:12.8}]}

ROBOT INPUT
Servoid:int
Servospeed: double between -1 and 1
-negative values represent a backwards motion
{“servos”:[{“servoid”:6, “servospeed”:0.5},{“servoid”:3,”servospeed”:-0.5}]}
ASU-VPL将编码控制信息放在JSON对象中,服务器解析这个脚本并执行它所定义的动作。同时也能够通过JSON将信息发送给ASU-VPL,ASU-VPL程序利用这个信息去定义接下来要进行的动作。
Galileo端采集到拓展IO对应的传感器信息通过无线方式传递给上位机,上位机得到后将处理后的动作指令传递给Galileo端。具体的数据操作可参见文档IntroductionVIPLE.pdf。
网络通信硬件部分采用PCIe无线网卡,Galileo与上位机可以连接外部路由或者以Galileo作为AP双方直接建立通信。软件部分以IP与Port做设备区别。如图所示为通信服务设置。

2.安卓手机客户端编写解析与发送json数据
安卓端发送json数据代码(左右轮调速与速度显示):
public void josnput()
{
JSONArray JsonArray = new JSONArray();
JSONObject jsonObject = new JSONObject();
JSONObject jsonObject1 = new JSONObject();
JSONObject jsonObject2 = new JSONObject();
try {
jsonObject.put(“servoId”, 6);
jsonObject.put(“servoSpeed”, leftspeed);
jsonObject1.put(“servoId”, 3);
jsonObject1.put(“servoSpeed”, rightspeed);
JsonArray.put(jsonObject);
JsonArray.put(jsonObject1);
jsonObject2.put(“servos”, JsonArray);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
安卓端解析json数据代码(超声波的测距值,红外避障模块值和循迹模块值):
try {
br = new BufferedReader(new InputStreamReader(tcpClisocket.getInputStream()));
new Thread(new Runnable() {
public void run() {
isConnect = true;
while(isConnect){
try {
line=br.readLine(); JSONObject jsonObjects = new JSONObject(line);
JSONArray jsonArray = jsonObjects.getJSONArray(“sensors”); JSONObject object0 = jsonArray.getJSONObject(0);
String ulst=”超声波测距距离:”+object0.getString(“value”)+”cm”+”\n”;
JSONObject object1 = jsonArray.getJSONObject(1);
String infrared=”红外蔽障开关值:”+object1.getString(“value”)+”\n”;
JSONObject object2 = jsonArray.getJSONObject(2);
String track=”循迹值:”+object2.getString(“value”);
setText(ulst+infrared+track);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}).start();
} catch (IOException e) {
// TODO Aut3o-generated catch block
e.printStackTrace();
}
如下图所示为安卓客户端设计结果图,采用相对布局,socket通信。
这里写图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值