很有意思,现在家家户户的老旧闲置手机太多了,这里提供了一种变废为宝的方法。
不会传视频,请看链接:
大家可以聊一聊啊,老旧闲置手机还有什么用处呢,比如用这种方法还可以做扫地机器人啊,智能窗帘啊什么的。
这种方法成本很低哦。UP主:https://space.bilibili.com/72236390/
手机固定在小车上,手机上的app通过摄像头寻找目标,如果找到目标,app就会计算出目标和小车之间的距离和角度,然后通过蓝牙向小车发送移动指令,让小车靠近目标。当小车靠近目标以后,手机app再向小车发送抓取或者推动等指令。如果app在当前位置没有发现目标,就给小车发送左转命令,然后继续寻找目标。
这里有很多机器人运行视频: https://space.bilibili.com/72236390/
这个项目是使用手机通过蓝牙连接机器人,然后手机发送指令控制机器人的。
app使用android studio 开发,这是蓝牙连接的代码:
public void connectBLE() {
if(BTdevice == null){
Log.e(TAG, "connectBLE Error: BTdevice == null ");
return;
}
Log.e(TAG, "connectBLE start ...");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
mBluetoothGatt = BTdevice.connectGatt(MainActivity.this,
true, gattCallback, TRANSPORT_LE);
} else {
mBluetoothGatt = BTdevice.connectGatt(MainActivity.this,
true, gattCallback);
}
}
这是断开蓝牙连接的代码:
public boolean disConnect() {
if (mBluetoothGatt != null)
{
mBluetoothGatt.disconnect();
mBluetoothGatt.close();
// mBluetoothGatt = null;
return true;
}
return false;
}
其中最重要的是这个callback:
private BluetoothGattCallback gattCallback = new BluetoothGattCallback() {
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
super.onConnectionStateChange(gatt, status, newState);
Log.e(TAG,"onConnectionStateChange()");
if (status==BluetoothGatt.GATT_SUCCESS){
//connect success
}else{
//connect fail
}
}
/**
* find device, really connect.
* */
@Override
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
super.onServicesDiscovered(gatt, status);
});
}
图像识别使用的opencv,关于他的环境搭建,网上有很多介绍,其中最重要的是这句:
@Override
public void onResume() {
super.onResume();
if (!OpenCVLoader.initDebug()) {
// Log.d(TAG, "Internal OpenCV library not found. Using OpenCV Manager for initialization");
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_0_0, this, mLoaderCallback);
} else {
// Log.d(TAG, "OpenCV library found inside package. Using it!");
mLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS);
}
}
我把它放在onResume(),使用非常方便。
来个视频,很爽,这种模式可以开发很多超低成本的人工智能应用,欢迎大家讨论,谢谢!
手机编程自主控制机器人完成各种任务。也是最新手机外设哦。