FEZ Cerbot 前後に動かす

FEZ Cerbot 前後に動かす



PWMの周期は10μ秒に設定されています。

Program.cs
using System;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Presentation.Shapes;
using Microsoft.SPOT.Touch;

using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;

namespace ForwardAndBackward
{
    public partial class Program
    {
        const int Left_SPEED = 60;
        const int Right_SPEED = 70;   
        int counter = 0;
        void ProgramStarted()
        {
            new Thread(DoRun).Start();
        }
        void DoRun()
        {
            GT.Timer timer = new GT.Timer(500, GT.Timer.BehaviorType.RunContinuously); 
            timer.Tick += new GT.Timer.TickEventHandler(timer_Tick);
            timer.Start();
        }
        void timer_Tick(GT.Timer timer)
        {
            if (++counter >= 6) counter = 0;
            if (counter < 3) cerbotController.SetMotorSpeed(Left_SPEED, Right_SPEED);
            else cerbotController.SetMotorSpeed(-Left_SPEED, -Right_SPEED);
        }
    }
}
 1 
 2 
 3 
 4 
 5 
 6 
 7 
 8 
 9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 値の最大は100、最少は30ぐらい
21 左右のモーターの特性が異なる
22 
23 ユーザーが作るプログラムのエントリーポイント
24 これが終了しないと正しいイベント処理ができない
25 らしいので、DoRunというスレッドを開始させる
26 
27 
28 タイマーでイベント処理のみを行うように設定する
29 500ミリ秒ごとにイベントが連続的に発生する
30 
31 
32 
33 実際の処理部分
34 500msec ×3 = 1.5秒ごとに前後動作を変更する
35 
36 
37 
38 
39 
40