ETロボコンシミュレータ 超音波センサー機能拡張


はじめに

ETロボコンシミュレータの超音波センサーに機能拡張を行いました。

動作の前提事項

  • ETロボコンシミュレータの環境構築すること
  • ARM版マイコンシミュレータで動作させること

環境の構築方法については、以下を参照してください。

  1. TOPPERS/箱庭デモ ETロボコンシミュレータ
  2. ARM版マイコンシミュレータを Mac/Linux/Windows 環境で自作した話

超音波センサの実装

UltrasonicSensor.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class UltrasonicSensor : MonoBehaviour
{
    private float contact_distance;
    public float distanceValue;
    // Start is called before the first frame update
    void Start()
    {
        contact_distance = 255;
    }

    // Update is called once per frame
    void Update()
    {
        //nothing to do
    }

    public void UpdateUltrasonicSensor()
    {
        this.distanceValue = contact_distance;
    }

    private void OnTriggerStay(Collider other)
    {

        GameObject FrontSensor = GameObject.Find("UltrasonicSensor");

        Vector3 Apoint = FrontSensor.transform.position;
        Vector3 Bpoint = other.gameObject.transform.position;

        // Distance between Sensor and Object
        contact_distance = Vector3.Distance(Apoint,Bpoint);
    }
}

Colliderがオブジェクトに接触するとオブジェクトと,超音波センサとの距離を取得します。

athrill側で、ev3_ultrasonic_sensor_get_distance (sensor_port_t port)を呼び出すことで、
unity上の超音波のセンサ値を取得することができます。

動作確認

unityをシミュレーションモードにして、
WSL上で、以下のコマンドを実行してください。

$ cd athrill-sample/ev3rt/ev3rt-beta7-release/asp_arm/sdk/OBJ1.1
$ make clean
$ make
$ athrill2 -c1 -m memory.txt -d device_config.txt -t -1 asp