動作を司るクラスを作る

BasicWheelクラス

 ステッピングモーターを意識せずに、直進、回転、ターンなどの動作をさせるクラスを作ります。

BasicWheelクラス
    class BasicWheel
    {
      bool forward = true;
      SteppingMotor R, L;
      public BasicWheel()
      {
        R = new SteppingMotor (GPIOPins.V2Plus_Pin_P1_33,
            GPIOPins.V2Plus_Pin_P1_31, forward);
        L = new SteppingMotor (GPIOPins.V2Plus_Pin_P1_32,
            GPIOPins.V2Plus_Pin_P1_36, !forward);
      }
      public void move(double pathway, int step)  // cm unit
      {
        SteppingMotor.TotalTime = Math.Abs(step) * (int)(pathway / SteppingMotor.oneStep + 0.5);
        Console.WriteLine("Straight ahead start {0}msec", SteppingMotor.TotalTime);

        R.MotorOn ();
        Stopwatch stopwatch = Stopwatch.StartNew ();
        R.Start(step);
        L.Start (step);
        while (!SteppingMotor.StopFlag);
        stopwatch.Stop ();
        long span = stopwatch.ElapsedTicks;
        Console.WriteLine("Straight end. Time={0,7:f3}sec", span/10e6);
        R.MotorOff();
        Thread.Sleep(100);
      }
    }
 1 
 2 
 3 
 4 
 5 
 6 
 7 
 8 
 9 
10 
11 
12 前進、後進するメソッド
13 pathway: 距離(cm)
14 step   : スピード
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 


直進するメインプログラム



直進するメインプログラム
      static void Main(string[] args)
      {
        BasicWheel robo = new BasicWheel ();
        robo.move (10.0, 3);
      }
 1 
 2 
 3 オブジェクトを作る
 4 10cm前進する
 5 

課題

上記のプログラムは回転、ターンの動作がありません。この動作をBasicWheelクラスに追加しなさい。また、動作は以下のメインプログラムが動くようにしなさい。
前後進、回転、ターン
    static void Main(string[] args)
    {
      BasicWheel robo = new BasicWheel ();
      robo.move (10.0, 3);
      robo.rotete(45, 5);
      robo.turn(6, 3, 6);
      robo.turn(-6, -3, 6);
      robo.rotete(-45, 5);
      robo.move (10.0, -3);
    }
 1 
 2 
 3 オブジェクトを作る
 4 10cm前進
 5 45度回転
 6 Rを6、Lを3のスピードで6cmターン
 7 Rを-6、Lを-3のスピードで6cmターン
 8 -45度回転
 9 10cm後進
10