0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

HiTechnic IR Seeker V2 拡張ブロック

Posted at

HTIRSeekerPLUS

HiTechnic IR Seeker V2 用の拡張ブロックを公開しました。
従来の「方向」や「強さ(明るさ)」の取得に加えて、スイッチブロックやループブロックでも使用できる 比較モード選択モード を追加しています。

以下のリンクからダウンロードできます:

背景

株式会社 Afrel さんの記事に載っていた IR Seeker V2 の拡張ブロックの配布リンク先が現在利用できなくなっており、また日本語 UI に対応したブロックも存在しなかったため、新しく作りました。

特徴

比較モード選択モード を追加することで、スイッチやループブロックでも直感的に使えるようになっています。また、日本語UIにもしっかりと対応しています。

Compare_Strength.jpg

README_Select_Direction.jpg

解説

ブロック作成の基本は、LEGO公式の EV3 ブロックデベロッパーキット を参照してください。
ここでは、比較モードと選択モードの設定方法を解説します。

比較モード・選択モードの設定方法

ブロック定義の <BlockInterface>Compare または Selector に設定すると、スイッチブロックやループブロックで利用可能になります。

方向選択モード

<!-- blocks.xml -->
<Block>
    <Mode>MeasureACDirection</Mode>
    <Reference Type="VILib" Name="MeasureACDirection.vix" />
    <ParameterReference Name="Port" />
    <ParameterReference Name="Direction" CompilerDirectives="Result"/>
    <PaletteInfo Weight="0.5" />
    <!-- Selectorに設定(スイッチで選択モードとして利用可能) -->
    <BlockInterface>Selector</BlockInterface>
    <Flags>PBROnly</Flags>
    <Hardware></Hardware>
</Block>

明るさ比較モード

<!-- blocks.xml -->
<Block>
    <Mode>CompareACStrength</Mode>
    <Reference Type="VILib" Name="CompareACStrength.vix" />
    <ParameterReference Name="Port" />
    <ParameterReference Name="Comparison" />
    <ParameterReference Name="Threshold" />
    <ParameterReference Name="Result" />
    <ParameterReference Name="Strength" />
    <!-- Compareに設定(ループ/スイッチ/待機ブロックで比較モードとして利用可能) -->
    <BlockInterface>Compare</BlockInterface>
    <Flags>PBROnly</Flags>
    <Hardware></Hardware>
</Block>

選択モードの画像設定

選択モードでは、値に応じてブロックの表示画像を切り替えることができます。
方法は以下の通りです。

1. 切り替え用画像の作成

切り替え用の画像を用意します。サイズは22×22ピクセル、ファイル名は、「値と画像の対応を記述するファイル名」+「識別子」.jpg の形式にしてください。

Identification_Direction.jpg

2. 値と画像の対応をXMLに記述

XMLファイルに値と表示名、表示画像の対応を記述します。

<!-- Identification_Direction.xml -->
<?xml version="1.0" encoding="utf-8"?>
<Definition Type="Integer">
    <Point Value="0" Name="0" ImageSuffix="_0" />
    <Point Value="1" Name="1" ImageSuffix="_1" />
    <Point Value="2" Name="2" ImageSuffix="_2" />
    <Point Value="3" Name="3" ImageSuffix="_3" />
    <Point Value="4" Name="4" ImageSuffix="_4" />
    <Point Value="5" Name="5" ImageSuffix="_5" />
    <Point Value="6" Name="6" ImageSuffix="_6" />
    <Point Value="7" Name="7" ImageSuffix="_7" />
    <Point Value="8" Name="8" ImageSuffix="_8" />
    <Point Value="9" Name="9" ImageSuffix="_9" />
</Definition>

3. パラメータ定義

blocks.xml で、上記XMLファイルをパラメータにリンクします。

<!-- blocks.xml -->
<Parameter 
    Name="Direction" 
    Direction="Output" 
    DataType="Single" 
    Identification="Identification_HTIRSeekerPLUS_Direction.png" 
    ValueDisplay="Identification_Direction.xml" 
    Configuration="Identification_Direction.xml" 
    ModeCanSpecifyProperties="True" 
/>

このあたりの設定方法は、EV3 ブロックデベロッパーキット に載っていないです。既存のセンサーブロック、特に標準カラーセンサーの設定を参考にすると、選択モードや比較モードの設定が理解しやすくなります。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?