HomeThreads.cs

Home multiple axes using threads.

/*  RecorderInterrupts.cs
 
 Copyright(c) 1998-2010 by Robotic Systems Integration, Inc. All rights reserved.
 This software contains proprietary and confidential information of Robotic 
 Systems Integration, Inc. (RSI) and its suppliers. Except as may be set forth 
 in the license agreement under which this software is supplied, disclosure, 
 reproduction, or use with controls other than those provided by RSI or suppliers
 for RSI is strictly prohibited without the prior express written consent of 
 Robotic Systems Integration.

 Warning!  This is a sample program to assist in the integration of your motion 
 controller with your application.  It may not contain all of the logic and safety
 features that your application requires.

 For any questions regarding this sample code please visit www.roboticsys.com.
 ==================================================================================

*/

using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using RSI.RapidCode.SynqNet.dotNET;
using RSI.RapidCode.SynqNet.dotNET.Enums;
using System.Threading;

namespace SampleApplications
{
  
    [TestFixture]
    public class HomeThreads
    {
        const int X = 0;                        // axis number
        const int Y = 1;                        // axis number
        const double INCREMENT = 100.0;
        const double VELOCITY = 1000.0;
        const double ACCEL = 10000.0;
        const double DECEL = ACCEL;
        const double JERKPCT = 50.0;
        const int TIMEOUT_MILLISECONDS = 1000;   // wait a second, then timeout

        const int MOVES = 10;  // how many moves to do for the test

        // RapidCode objects
        MotionController controller;
        AxisThread xThread;
        AxisThread yThread;
        



 


        [Test]
        public void Main()
        {
            try
            {
                controller = MotionController.Create();
                xThread = new AxisThread(controller.AxisGet(X));
                yThread = new AxisThread(controller.AxisGet(Y));



    
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }




        public class AxisThread
        {
            Axis axis;
            Thread thread;

            public AxisThread(Axis axis)
            {
                this.axis = axis;
                this.axis.InterruptEnableSet(true);
                this.axis.InterruptMaskClear(); // turn of notification from all interrupts
                this.axis.InterruptMaskOnSet(RSIEventType.RSIEventTypeMOTION_DONE);  // interrupt only when motion done
            }

            public void MoveRelative()
            {
                RSIEventType interrupt;
                axis.MoveRelative(INCREMENT, VELOCITY, ACCEL, DECEL, JERKPCT);

                interrupt = axis.InterruptWait(TIMEOUT_MILLISECONDS);  // sleeps thread until interrupt or timeout

                switch (interrupt)
                {
                    case RSIEventType.RSIEventTypeMOTION_DONE:
                        Console.WriteLine("Motion Done on Axis " + axis.NumberGet());
                        break;
                    default:
                        Console.WriteLine("Motion failed.");
                        break;
                }
            }

        }

    }
}