コード例 #1
0
        /// <summary>
        /// Create a robot command from a MoveTool command.  Adjusts for robot specific
        /// max speeds.  May return null if there is no effective move.
        /// </summary>
        /// <param name="m"></param>
        /// <returns></returns>
        private IRobotCommand CreateRobotCommand(MoveTool m, ICommandGenerator c)
        {
            var p = m.Target;

            p.Z += z_offset;

            float inches_per_minute = m.Speed == MoveTool.SpeedType.Cutting ? MaxCutSpeed : MaxRapidSpeed;

            Vector3 delta = lastPosition - p;

            lastPosition = p;

            if (delta.Length > 0)
            {
                if (Math.Abs(delta.Z) > 0.0001f)
                {
                    inches_per_minute = Math.Min(MaxZSpeed, inches_per_minute);
                }
                return(c.GenerateMoveCommand(p, inches_per_minute / 60.0f));
            }
            else
            {
                Console.WriteLine("Ignoring command with length of 0");
                return(null);
            }
        }
コード例 #2
0
ファイル: Robot.cs プロジェクト: JackTing/PathCAM
 public Robot(SerialPortWrapper serial)
 {
     commandGenerator = null;
     this.serial = serial;
     serial.newDataAvailable += new SerialPortWrapper.newDataAvailableDelegate(NewDataAvailable);
     t = new Timer();
     t.Interval = 50;
     t.Start();
     t.Elapsed += new ElapsedEventHandler(t_Elapsed);
 }
コード例 #3
0
 public Robot(SerialPortWrapper serial)
 {
     commandGenerator         = null;
     this.serial              = serial;
     serial.newDataAvailable += new SerialPortWrapper.newDataAvailableDelegate(NewDataAvailable);
     t          = new Timer();
     t.Interval = 50;
     t.Start();
     t.Elapsed += new ElapsedEventHandler(t_Elapsed);
 }
コード例 #4
0
            internal override bool ProcessResponse(byte data)
            {
                if (data == 0xCA) // Only the binary robot will send this character (it's the packet start character)
                {
                    // Drop anything earlier from the accumulator
                    accumulator.Clear();
                    Console.WriteLine("Found 0xCA start byte, looks like the packetized binary protocol");
                    commandGenerator    = new PacketizedCommandGenerator();
                    binaryStatusCommand = commandGenerator.GenerateStatusCommand();
                }

                accumulator.Add(data);
                if (binaryStatusCommand != null)
                {
                    // The response will be a binary status command, just forward the data and wait until it's good.
                    return(binaryStatusCommand.ProcessResponse(data));
                }
                else
                {
                    // Look for an ASCII communicating robot (like GRBL)
                    var s = System.Text.Encoding.ASCII.GetString(accumulator.ToArray());

                    if (s.EndsWith("\r\n", StringComparison.OrdinalIgnoreCase))
                    {
                        if (s.StartsWith("Grbl ") && s.Length >= 9)
                        {
                            var   version       = s.Substring(5, 3);
                            float version_float = 0.0f;
                            if (float.TryParse(version, out version_float) && version_float >= 0.8f)
                            {
                                Console.WriteLine("Compatible Grbl type robot found: " + s.Substring(0, 9));
                                commandGenerator = new GrblCommandGenerator();
                                return(true);
                            }
                        }
                        else
                        {
                            // Seems like a GRBL type robot, but the start of the string wasn't right.  Maybe some garbage
                            // or an extra \r\n, clear it out and wait for more.
                            accumulator.Clear();
                        }
                    }
                }
                return(false);
            }
コード例 #5
0
        private void NewDataAvailable(byte data)
        {
            lock (thisLock)
            {
                elapsedCounter = 0;
                if (currentCommand == null)
                {
                    Console.WriteLine("Error: Received data, but no command was sent!");
                    Console.Write(data.ToString("x") + ", ");
                    Console.WriteLine();
                }
                else
                {
                    if (currentCommand.ProcessResponse(data))
                    {
                        bool canAcceptMoveCommand = false;
                        if (currentCommand is IRobotCommandWithStatus)
                        {
                            IRobotCommandWithStatus status = currentCommand as IRobotCommandWithStatus;
                            currentPosition      = status.CurrentPosition;
                            canAcceptMoveCommand = status.CanAcceptMoveCommand;
                            if (this.lastPositionKnown == false)
                            {
                                lastPosition      = currentPosition;
                                lastPositionKnown = true;
                            }
                            if (onRobotStatusChange != null)
                            {
                                onRobotStatusChange(status, EventArgs.Empty);
                            }
                        }
                        else if (currentCommand is RobotDetectionCommand)
                        {
                            RobotDetectionCommand r = currentCommand as RobotDetectionCommand;
                            commandGenerator = r.GetCommandGenerator();
                        }

                        currentCommand = GetNextCommand(canAcceptMoveCommand);
                        serial.Transmit(currentCommand.GenerateCommand());
                    }
                }
            }
        }
コード例 #6
0
        void t_Elapsed(object sender, ElapsedEventArgs e)
        {
            t.Stop();
            lock (thisLock)
            {
                if (elapsedCounter > timeout_ms)
                {
                    if (currentCommand != null && currentCommand is RobotDetectionCommand)
                    {
                        Console.WriteLine("Unexpected Response from robot detection: " + (currentCommand as RobotDetectionCommand).DumpData());
                    }
                    // Expected reply not received within 1 second, assume command was lost.
                    Console.WriteLine("Device Timeout!");
                }

                if (serial == null || !serial.IsOpen || elapsedCounter > timeout_ms)
                {
                    lastPositionKnown = false;
                    commandGenerator  = null;
                    currentCommand    = null;
                    elapsedCounter    = 0;
                }
                else
                {
                    if (currentCommand == null)
                    {
                        currentCommand = new RobotDetectionCommand();
                        serial.Transmit(currentCommand.GenerateCommand());
                        elapsedCounter = 0;
                    }
                    else
                    {
                        elapsedCounter += 50;
                    }
                }
            }
            t.Start();
        }
コード例 #7
0
ファイル: Robot.cs プロジェクト: JackTing/PathCAM
            internal override bool ProcessResponse(byte data)
            {
                if (data == 0xCA) // Only the binary robot will send this character (it's the packet start character)
                {
                    // Drop anything earlier from the accumulator
                    accumulator.Clear();
                    Console.WriteLine("Found 0xCA start byte, looks like the packetized binary protocol");
                    commandGenerator = new PacketizedCommandGenerator();
                    binaryStatusCommand = commandGenerator.GenerateStatusCommand();
                }

                accumulator.Add(data);
                if (binaryStatusCommand != null)
                {
                    // The response will be a binary status command, just forward the data and wait until it's good.
                    return binaryStatusCommand.ProcessResponse(data);
                }
                else
                {
                    // Look for an ASCII communicating robot (like GRBL)
                    var s = System.Text.Encoding.ASCII.GetString(accumulator.ToArray());

                    if (s.EndsWith("\r\n", StringComparison.OrdinalIgnoreCase))
                    {
                        if (s.StartsWith("Grbl ") && s.Length >= 9)
                        {
                            var version = s.Substring(5, 3);
                            float version_float = 0.0f;
                            if (float.TryParse(version, out version_float) && version_float >= 0.8f)
                            {
                                Console.WriteLine("Compatible Grbl type robot found: " + s.Substring(0, 9));
                                commandGenerator = new GrblCommandGenerator();
                                return true;
                            }
                        }
                        else
                        {
                            // Seems like a GRBL type robot, but the start of the string wasn't right.  Maybe some garbage
                            // or an extra \r\n, clear it out and wait for more.
                            accumulator.Clear();
                        }
                    }
                }
                return false;
            }
コード例 #8
0
ファイル: Robot.cs プロジェクト: JackTing/PathCAM
        void t_Elapsed(object sender, ElapsedEventArgs e)
        {
            t.Stop();
            lock (thisLock)
            {
                if (elapsedCounter > timeout_ms)
                {
                    if (currentCommand != null && currentCommand is RobotDetectionCommand)
                    {
                        Console.WriteLine("Unexpected Response from robot detection: " + (currentCommand as RobotDetectionCommand).DumpData());
                    }
                    // Expected reply not received within 1 second, assume command was lost.
                    Console.WriteLine("Device Timeout!");
                }

                if (serial == null || !serial.IsOpen || elapsedCounter > timeout_ms)
                {
                    lastPositionKnown = false;
                    commandGenerator = null;
                    currentCommand = null;
                    elapsedCounter = 0;
                }
                else
                {
                    if (currentCommand == null)
                    {
                        currentCommand = new RobotDetectionCommand();
                        serial.Transmit(currentCommand.GenerateCommand());
                        elapsedCounter = 0;
                    }
                    else
                    {
                        elapsedCounter += 50;
                    }
                }
            }
            t.Start();
        }
コード例 #9
0
ファイル: Robot.cs プロジェクト: JackTing/PathCAM
        private void NewDataAvailable(byte data)
        {
            lock (thisLock)
            {
                elapsedCounter = 0;
                if (currentCommand == null)
                {
                    Console.WriteLine("Error: Received data, but no command was sent!");
                    Console.Write(data.ToString("x") + ", ");
                    Console.WriteLine();
                }
                else
                {
                    if (currentCommand.ProcessResponse(data))
                    {
                        bool canAcceptMoveCommand = false;
                        if (currentCommand is IRobotCommandWithStatus)
                        {
                            IRobotCommandWithStatus status = currentCommand as IRobotCommandWithStatus;
                            currentPosition = status.CurrentPosition;
                            canAcceptMoveCommand = status.CanAcceptMoveCommand;
                            if (this.lastPositionKnown == false)
                            {
                                lastPosition = currentPosition;
                                lastPositionKnown = true;
                            }
                            if (onRobotStatusChange != null)
                            {
                                onRobotStatusChange(status, EventArgs.Empty);
                            }
                        }
                        else if (currentCommand is RobotDetectionCommand)
                        {
                            RobotDetectionCommand r = currentCommand as RobotDetectionCommand;
                            commandGenerator = r.GetCommandGenerator();
                        }

                        currentCommand = GetNextCommand(canAcceptMoveCommand);
                        serial.Transmit(currentCommand.GenerateCommand());
                    }
                }
            }
        }
コード例 #10
0
ファイル: Robot.cs プロジェクト: JackTing/PathCAM
        /// <summary>
        /// Create a robot command from a MoveTool command.  Adjusts for robot specific
        /// max speeds.  May return null if there is no effective move.
        /// </summary>
        /// <param name="m"></param>
        /// <returns></returns>
        private IRobotCommand CreateRobotCommand(MoveTool m, ICommandGenerator c)
        {
            var p = m.Target;
            p.Z += z_offset;

            float inches_per_minute = m.Speed == MoveTool.SpeedType.Cutting ? MaxCutSpeed : MaxRapidSpeed;

            Vector3 delta = lastPosition - p;
            lastPosition = p;

            if (delta.Length > 0)
            {
                if (Math.Abs(delta.Z) > 0.0001f)
                {
                    inches_per_minute = Math.Min(MaxZSpeed, inches_per_minute);
                }
                return c.GenerateMoveCommand(p, inches_per_minute / 60.0f);
            }
            else
            {
                Console.WriteLine("Ignoring command with length of 0");
                return null;
            }
        }