Ejemplo n.º 1
0
    public void HandleCommand(ZACommons commons, EventDriver eventDriver,
                              string argument, Action <ZACommons, Vector3D> targetAction)
    {
        argument = argument.Trim().ToLower();
        switch (argument)
        {
        case "compute":
            var firstReference = GetReference(commons, STATIC_REFERENCE_GROUP);
            var rotorReference = GetReference(commons, ROTOR_REFERENCE_GROUP);

            var      first = new Rangefinder.LineSample(firstReference);
            var      second = new Rangefinder.LineSample(rotorReference);
            Vector3D closestFirst, closestSecond;
            if (Rangefinder.Compute(first, second, out closestFirst, out closestSecond))
            {
                // Take midpoint of closestFirst-closestSecond segment
                var target = (closestFirst + closestSecond) / 2.0;
                targetAction(commons, target);
            }
            break;

        default:
            rotorStepper.HandleCommand(commons, eventDriver, argument);
            break;
        }
    }
Ejemplo n.º 2
0
    public void HandleCommand(ZACommons commons, EventDriver eventDriver,
                              string argument, Action<ZACommons, Vector3D> targetAction)
    {
        argument = argument.Trim().ToLower();
        switch (argument)
        {
            case "compute":
                var firstReference = GetReference(commons, STATIC_REFERENCE_GROUP);
                var rotorReference = GetReference(commons, ROTOR_REFERENCE_GROUP);

                var first = new Rangefinder.LineSample(firstReference);
                var second = new Rangefinder.LineSample(rotorReference);
                Vector3D closestFirst, closestSecond;
                if (Rangefinder.Compute(first, second, out closestFirst, out closestSecond))
                {
                    // Take midpoint of closestFirst-closestSecond segment
                    var target = (closestFirst + closestSecond) / 2.0;
                    targetAction(commons, target);
                }
                break;
            default:
                rotorStepper.HandleCommand(commons, eventDriver, argument);
                break;
        }
    }
Ejemplo n.º 3
0
    public void HandleCommand(ZACommons commons, string argument)
    {
        argument = argument.Trim().ToLower();
        var parts = argument.Split(new char[] { ' ' }, 2);
        if (parts.Length < 2 || parts[0] != "rfinder") return;
        var command = parts[1];

        switch(command)
        {
            case "origin":
                {
                    var reference = GetReference(commons);
                    if (reference == null) return;
                    Origin = new Rangefinder.LineSample(reference);
                    Last = null;
                    Result.Clear();
                    break;
                }
            case "snapshot":
                {
                    var reference = GetReference(commons);
                    if (reference == null) return;
                    var second = new Rangefinder.LineSample(reference);

                    Last = null;
                    Result.Clear();

                    Vector3D closestFirst, closestSecond;
                    if (Rangefinder.Compute(Origin, second, out closestFirst,
                                            out closestSecond))
                    {
                        var target = (closestFirst + closestSecond) / 2.0;
                        Last = target;

                        Result.Append(string.Format("Target: {0:F2}, {1:F2}, {2:F2}",
                                                    target.GetDim(0),
                                                    target.GetDim(1),
                                                    target.GetDim(2)));
                        Result.Append('\n');

                        var targetVector = target - reference.GetPosition();
                        Result.Append(string.Format("Distance: {0} m", (ulong)(targetVector.Length() + 0.5)));

                        TargetAction(commons, target);
                    }
                    else
                    {
                        Result.Append("Parallel lines???");
                    }
                    break;
                }
            case "restore":
                if (Last != null)
                {
                    TargetAction(commons, (Vector3D)Last);
                }
                break;
        }
    }
Ejemplo n.º 4
0
    public void HandleCommand(ZACommons commons, string argument)
    {
        argument = argument.Trim().ToLower();
        var parts = argument.Split(new char[] { ' ' }, 2);

        if (parts.Length < 2 || parts[0] != "rfinder")
        {
            return;
        }
        var command = parts[1];

        switch (command)
        {
        case "origin":
        {
            var reference = GetReference(commons);
            if (reference == null)
            {
                return;
            }
            Origin = new Rangefinder.LineSample(reference);
            Last   = null;
            Result.Clear();
            break;
        }

        case "snapshot":
        {
            var reference = GetReference(commons);
            if (reference == null)
            {
                return;
            }
            var second = new Rangefinder.LineSample(reference);

            Last = null;
            Result.Clear();

            Vector3D closestFirst, closestSecond;
            if (Rangefinder.Compute(Origin, second, out closestFirst,
                                    out closestSecond))
            {
                var target = (closestFirst + closestSecond) / 2.0;
                Last = target;

                Result.Append(string.Format("Target: {0:F2}, {1:F2}, {2:F2}",
                                            target.GetDim(0),
                                            target.GetDim(1),
                                            target.GetDim(2)));
                Result.Append('\n');

                var targetVector = target - reference.GetPosition();
                Result.Append(string.Format("Distance: {0} m", (ulong)(targetVector.Length() + 0.5)));

                TargetAction(commons, target);
            }
            else
            {
                Result.Append("Parallel lines???");
            }
            break;
        }

        case "restore":
            if (Last != null)
            {
                TargetAction(commons, (Vector3D)Last);
            }
            break;
        }
    }