【Androidアプリ】モノのインターネットの実戦プロジェクトの自動運転スマートカー(ソースコードとデモンストレーション超詳細付き)

ソースコードが必要な場合は、コレクションを気に入ってフォローし、コメント領域にプライベートメッセージを残してください~~~~

今日の社会は Internet of Everything の時代に突入しており、その技術的基盤は主に 5G、モノのインターネット、人工知能に由来しています。この 3 つの統合により、多くの新製品が生み出されましたが、その中で最も輝かしいのが自動運転電気自動車であり、最新の技術とエンジニアリングの実践の成果を結集し、Huawei、Xiaomi、Baidu、アリ、テンセントが続々と参入。なぜこれらのテクノロジーの巨人は、自動車の製造に熱心なのですか? 重要な理由は、スマートカーがモバイルインターネットと密接に関連していることです.スマート電気自動車と従来のガソリン車の違いは、スマートフォンとフィーチャーフォンの違いのようなものです.これがどれほど破壊的で革新的な技術であるかは想像に難くありません.

1. 要件の説明

自動運転を実現するためには、スマートカーが適切に動作するために次の機能が必要です。

(1) 要件を満たす道路を自動的に走行します。

(2) 障害物に遭遇した場合、積極的に衝突を回避できなければなりません。

(3) 命令や命令に従い、外部からの指示を受けて運転状態を変更できること。

2.機能分析

車の組み立て効果は次のとおりで、読者は淘宝網などのプラットフォームに行って今回購入できます。

 

トロリーには、次の 3 つのインテリジェント モジュールが含まれています。

1) 赤外線追跡モジュール追跡モジュールは、赤外線反射センサーを使用して、赤外線に対する道路の反射率が目標しきい値内にあるかどうかを確認します。 

このモジュールは、車の下の道路の色を検出してルートを決定します.検出方式は、赤外線反射センサーを使用して、赤外線に対する道路の反射率が目標のしきい値内にあるかどうかを確認します.反射距離の範囲は2 mmから30です.んん。

(2) 赤外線障害物回避モジュール 障害物回避モジュールは、車の前方に障害物があるかどうかを検出し、障害物を回避するために経路を変更するかどうかを決定します。

このモジュールは、赤外線ラピッド グラウンドの原理に似ており、車の前方に障害物があるかどうかを検出して、ルートを変更して障害物を回避するかどうかを決定します。

(3) Bluetoothリモコンモジュールの操作者が携帯電話からBluetooth信号を車に送信し、車はBluetooth信号を受信後、指示に従って走行状態を調整する。

車両がリモート コントロール モジュールに接続された後、オペレーターは携帯電話を使用して Bluetooth 信号を車両に送信し、Bluetooth 信号を受信した後、車両は指示に従って運転状態を調整します。今回は、Wireshark を介して 2 つの BLE デバイス間の通信パケットをキャプチャします。

3.エフェクト表示

電話に正常に接続されました 

 モーターの馬力を携帯電話で制御して、加速または減速を実現できます

 

 実際のデモ効果は以下の通り

 
 4.コード

コードの一部は次のとおりです.すべてのソースコードが必要な場合は、コレクションをいいねしてフォローし、コメント領域にメッセージを残してください~~~~

package com.example.iot;

import androidx.appcompat.app.AppCompatActivity;

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothManager;
import android.bluetooth.le.BluetoothLeScanner;
import android.bluetooth.le.ScanCallback;
import android.bluetooth.le.ScanResult;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import android.util.Log;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.iot.adapter.BlueListAdapter;
import com.example.iot.bean.BlueDevice;
import com.example.iot.util.BluetoothUtil;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ScanCarActivity extends AppCompatActivity implements CompoundButton.OnCheckedChangeListener {
    private static final String TAG = "ScanCarActivity";
    private CheckBox ck_bluetooth; // 声明一个复选框对象
    private TextView tv_discovery; // 声明一个文本视图对象
    private ListView lv_bluetooth; // 声明一个用于展示蓝牙设备的列表视图对象
    private BlueListAdapter mListAdapter; // 声明一个蓝牙设备的列表适配器对象

    private Map<String, BlueDevice> mDeviceMap = new HashMap<>(); // 蓝牙设备映射
    private List<BlueDevice> mDeviceList = new ArrayList<>(); // 蓝牙设备列表
    private Handler mHandler = new Handler(Looper.myLooper()); // 声明一个处理器对象
    private BluetoothAdapter mBluetoothAdapter; // 声明一个蓝牙适配器对象
    private boolean isScaning = false; // 是否正在扫描

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_scan_car);
        initView(); // 初始化视图
        initBluetooth(); // 初始化蓝牙适配器
        if (BluetoothUtil.getBlueToothStatus()) { // 已经打开蓝牙
            ck_bluetooth.setChecked(true);
        }
    }

    // 初始化视图
    private void initView() {
        ck_bluetooth = findViewById(R.id.ck_bluetooth);
        tv_discovery = findViewById(R.id.tv_discovery);
        lv_bluetooth = findViewById(R.id.lv_bluetooth);
        ck_bluetooth.setOnCheckedChangeListener(this);
        mListAdapter = new BlueListAdapter(this, mDeviceList);
        lv_bluetooth.setAdapter(mListAdapter);
        lv_bluetooth.setOnItemClickListener((parent, view, position, id) -> {
            BlueDevice item = mDeviceList.get(position);
            Intent intent = new Intent(this, SmartCarActivity.class);
            intent.putExtra("address", item.address);
            startActivity(intent);
        });
    }

    // 初始化蓝牙适配器
    private void initBluetooth() {
        if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
            Toast.makeText(this, "当前设备不支持低功耗蓝牙", Toast.LENGTH_SHORT).show();
            finish(); // 关闭当前页面
        }
        // 获取蓝牙管理器,并从中得到蓝牙适配器
        BluetoothManager bm = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
        mBluetoothAdapter = bm.getAdapter(); // 获取蓝牙适配器
    }

    // 创建一个开启BLE扫描的任务
    private Runnable mScanStart = new Runnable() {
        @Override
        public void run() {
            if (!isScaning && BluetoothUtil.getBlueToothStatus()) {
                isScaning = true;
                // 获取BLE设备扫描器
                BluetoothLeScanner scanner = mBluetoothAdapter.getBluetoothLeScanner();
                scanner.startScan(mScanCallback); // 开始扫描BLE设备
                tv_discovery.setText("点击BLE设备进入管理界面");
            } else {
                mHandler.postDelayed(this, 2000);
            }
        }
    };

    // 创建一个扫描回调对象
    private ScanCallback mScanCallback = new ScanCallback() {
        @Override
        public void onScanResult(int callbackType, ScanResult result) {
            super.onScanResult(callbackType, result);
            if (TextUtils.isEmpty(result.getDevice().getName())) {
                return;
            }
            Log.d(TAG, "callbackType="+callbackType+", result="+result.toString());
            // 下面把找到的蓝牙设备添加到设备映射和设备列表
            BlueDevice device = new BlueDevice(result.getDevice().getName(), result.getDevice().getAddress(), 0);
            mDeviceMap.put(device.address, device);
            mDeviceList.clear();
            mDeviceList.addAll(mDeviceMap.values());
            runOnUiThread(() -> mListAdapter.notifyDataSetChanged());
        }

        @Override
        public void onBatchScanResults(List<ScanResult> results) {
            super.onBatchScanResults(results);
        }

        @Override
        public void onScanFailed(int errorCode) {
            super.onScanFailed(errorCode);
        }
    };

    // 创建一个停止BLE扫描的任务
    private Runnable mScanStop = () -> {
        isScaning = false;
        // 获取BLE设备扫描器
        BluetoothLeScanner scanner = mBluetoothAdapter.getBluetoothLeScanner();
        scanner.stopScan(mScanCallback); // 停止扫描BLE设备
    };

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        if (buttonView.getId() == R.id.ck_bluetooth) {
            if (isChecked) { // 开启蓝牙功能
                ck_bluetooth.setText("蓝牙开");
                if (!BluetoothUtil.getBlueToothStatus()) { // 还未打开蓝牙
                    BluetoothUtil.setBlueToothStatus(true); // 开启蓝牙功能
                }
                mHandler.post(mScanStart); // 启动开始BLE扫描的任务
            } else { // 关闭蓝牙功能
                ck_bluetooth.setText("蓝牙关");
                mHandler.removeCallbacks(mScanStart); // 移除开始BLE扫描的任务
                BluetoothUtil.setBlueToothStatus(false); // 关闭蓝牙功能
                mDeviceList.clear();
                mListAdapter.notifyDataSetChanged();
            }
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mHandler.removeCallbacks(mScanStart); // 移除开始BLE扫描的任务
        mHandler.removeCallbacks(mScanStop); // 移除停止BLE扫描的任务
    }

}

作るのは簡単ではありませんが、参考にしてください。いいね、フォロー、収集してください~~~

おすすめ

転載: blog.csdn.net/jiebaoshayebuhui/article/details/128147493