Пример #1
0
        /// <summary>
        /// Reads information from the Jrk and displays it in the textboxes.
        /// </summary>
        void DisplayStatus()
        {
            jrkVariables vars = jrk.getVariables();

            TargetTextBox.Text         = vars.target.ToString();
            ScaledFeedbackTextBox.Text = vars.scaledFeedback.ToString();
        }
Пример #2
0
        // Pulls data from the devices and places it in the table created earlier.
        public static void updateTable(DataGridView dataTable)
        {
            DataTable flippedStatusValues = new DataTable();
            string    period;

            //
            // PULLING DATA FROM MAESTRO
            //
            statusValues.Clear();
            if (NumOfConnectedMaestros > 0)
            {
                usc.getVariables(out maestroVars, out stack, out call_stack, out servos);
                errors = "";
                foreach (var error in Enum.GetValues(typeof(uscError)))
                {
                    if ((maestroVars.errors & (1 << (int)(uscError)error)) != 0)
                    {
                        errors += (error.ToString() + ", ");
                    }
                }
                //
                //
                // Need to add data information for other values, if needed
                //
                //
                statusValues.Rows.Add("Maestro", usc.getSerialNumber(), errors, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1);
            }
            // Case for when there are no connected Maestros
            else
            {
                statusValues.Rows.Add("Maestro", "No Maestros Found", "", -1, -1, -1, -1, -1, -1, -1, -1, -1, -1);
            }

            //
            // PULLING DATA FROM JRK 1
            //
            if (Program.NumOfConnectedJrks > 0 && usc.servoCount > 0)
            {
                // Preparing Jrk data input
                jrkVars = Jrk1.getVariables();

                // Reading Jrk current
                // Easier to store in a variable before sending to the table.
                currentCalibrationForward = (Byte)Jrk1.getJrkParameter(jrkParameter.PARAMETER_MOTOR_CURRENT_CALIBRATION_FORWARD);
                currentCalibrationReverse = (Byte)Jrk1.getJrkParameter(jrkParameter.PARAMETER_MOTOR_CURRENT_CALIBRATION_REVERSE);
                current = currentToMilliamps(Jrk1, jrkVars.current, jrkVars.dutyCycle);

                // Reading Jrk errors
                // It's easier to store them all in one variable before sending to the table.
                errors = "";
                if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_AWAITING_COMMAND))
                {
                    errors += "Awaiting command, ";
                }
                if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_NO_POWER))
                {
                    errors += "No power, ";
                }
                if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_MOTOR_DRIVER))
                {
                    errors += "Motor driver error, ";
                }
                if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_INPUT_INVALID))
                {
                    errors += "Input invalid, ";
                }
                if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_INPUT_DISCONNECT))
                {
                    errors += "Input disconnect";
                }
                if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_FEEDBACK_DISCONNECT))
                {
                    errors += "Feedback disconnect, ";
                }
                if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_MAXIMUM_CURRENT_EXCEEDED))
                {
                    errors += "Max. current exceeded, ";
                }
                if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_SERIAL_SIGNAL))
                {
                    errors += "Serial signal error, ";
                }
                if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_SERIAL_OVERRUN))
                {
                    errors += "Serial overrun, ";
                }
                if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_SERIAL_BUFFER_FULL))
                {
                    errors += "Serial RX buffer full, ";
                }
                if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_SERIAL_CRC))
                {
                    errors += "Serial CRC error, ";
                }
                if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_SERIAL_PROTOCOL))
                {
                    errors += "Serial protocol error, ";
                }
                if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_SERIAL_TIMEOUT))
                {
                    errors += "Serial timeout error, ";
                }

                period = servos[0].position * 0.25 + " microseconds";

                //Setting up the table with values
                statusValues.Rows.Add("Jrk", Jrk1.getSerialNumber(), errors, servos[0].position, period, jrkVars.target, jrkVars.scaledFeedback, jrkVars.feedback,
                                      jrkVars.errorSum, jrkVars.dutyCycleTarget, jrkVars.dutyCycle, servos[0].speed, servos[0].acceleration, current);
            }
            else
            {
                statusValues.Rows.Add("Jrk", "No Jrks Found");
            }

            //
            // PULLING DATA FROM JRK 2
            //
            if (Program.NumOfConnectedJrks > 1)
            {
                //Preparing Jrk data input
                jrkVars = Jrk2.getVariables();

                //Reading Jrk current
                // Easier to store in a variable before sending to the table.
                currentCalibrationForward = (Byte)Jrk2.getJrkParameter(jrkParameter.PARAMETER_MOTOR_CURRENT_CALIBRATION_FORWARD);
                currentCalibrationReverse = (Byte)Jrk2.getJrkParameter(jrkParameter.PARAMETER_MOTOR_CURRENT_CALIBRATION_REVERSE);
                current = currentToMilliamps(Jrk2, jrkVars.current, jrkVars.dutyCycle);

                //Reading Jrk errors
                // It's easier to store them all in one variable before sending to the table.
                errors = "";
                if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_AWAITING_COMMAND))
                {
                    errors += "Awaiting command, ";
                }
                if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_NO_POWER))
                {
                    errors += "No power, ";
                }
                if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_MOTOR_DRIVER))
                {
                    errors += "Motor driver error, ";
                }
                if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_INPUT_INVALID))
                {
                    errors += "Input invalid, ";
                }
                if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_INPUT_DISCONNECT))
                {
                    errors += "Input disconnect";
                }
                if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_FEEDBACK_DISCONNECT))
                {
                    errors += "Feedback disconnect, ";
                }
                if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_MAXIMUM_CURRENT_EXCEEDED))
                {
                    errors += "Max. current exceeded, ";
                }
                if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_SERIAL_SIGNAL))
                {
                    errors += "Serial signal error, ";
                }
                if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_SERIAL_OVERRUN))
                {
                    errors += "Serial overrun, ";
                }
                if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_SERIAL_BUFFER_FULL))
                {
                    errors += "Serial RX buffer full, ";
                }
                if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_SERIAL_CRC))
                {
                    errors += "Serial CRC error, ";
                }
                if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_SERIAL_PROTOCOL))
                {
                    errors += "Serial protocol error, ";
                }
                if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_SERIAL_TIMEOUT))
                {
                    errors += "Serial timeout error, ";
                }

                period = servos[1].position * 0.25 + " microseconds";

                //Setting up the table with values
                statusValues.Rows.Add("Jrk", Jrk1.getSerialNumber(), errors, servos[1].position, period, jrkVars.target, jrkVars.scaledFeedback, jrkVars.feedback,
                                      jrkVars.errorSum, jrkVars.dutyCycleTarget, jrkVars.dutyCycle, servos[1].speed, servos[1].acceleration, current);
            }

            //Future extension to more devices

            /*
             * if (Program.NumOfConnectedJrks > 2)
             * {
             * }
             * if (Program.NumOfConnectedJrks > 3)
             * {
             * }
             */

            flippedStatusValues.Columns.Add("");
            string deviceTrack = "";

            for (int i = 0; i < statusValues.Rows.Count; i++)
            {
                deviceTrack = "Device " + i;
                flippedStatusValues.Columns.Add(deviceTrack);
            }

            for (int i = 0; i < statusValues.Columns.Count; i++)
            {
                DataRow newRow = flippedStatusValues.NewRow();

                newRow[0] = statusValues.Columns[i].Caption;
                for (int j = 0; j < statusValues.Rows.Count; j++)
                {
                    newRow[j + 1] = statusValues.Rows[j][i];
                }
                flippedStatusValues.Rows.Add(newRow);
            }

            // Configuring the table to show the data
            dataTable.DataSource = flippedStatusValues;
        }
        private void printTimer_Tick(object sender, EventArgs e)
        {
            printTimer.Stop();

            // Preparing Jrk and Maestro data input
            jrkVars = Program.Jrk1.getVariables();
            Program.usc.getVariables(out maestroVars, out stack, out call_stack, out servos);

            // Reading Jrk current
            // Easier to store in a variable before sending to the table.
            Program.currentCalibrationForward = (Byte)Program.Jrk1.getJrkParameter(jrkParameter.PARAMETER_MOTOR_CURRENT_CALIBRATION_FORWARD);
            Program.currentCalibrationReverse = (Byte)Program.Jrk1.getJrkParameter(jrkParameter.PARAMETER_MOTOR_CURRENT_CALIBRATION_REVERSE);
            Program.current = Program.currentToMilliamps(Program.Jrk1, jrkVars.current, jrkVars.dutyCycle);

            // Reading Jrk errors
            // It's easier to store them all in one variable before sending to the table.
            Program.errors = "";
            if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_AWAITING_COMMAND))
            {
                Program.errors += "Awaiting command, ";
            }
            if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_NO_POWER))
            {
                Program.errors += "No power, ";
            }
            if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_MOTOR_DRIVER))
            {
                Program.errors += "Motor driver error, ";
            }
            if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_INPUT_INVALID))
            {
                Program.errors += "Input invalid, ";
            }
            if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_INPUT_DISCONNECT))
            {
                Program.errors += "Input disconnect";
            }
            if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_FEEDBACK_DISCONNECT))
            {
                Program.errors += "Feedback disconnect, ";
            }
            if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_MAXIMUM_CURRENT_EXCEEDED))
            {
                Program.errors += "Max. current exceeded, ";
            }
            if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_SERIAL_SIGNAL))
            {
                Program.errors += "Serial signal error, ";
            }
            if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_SERIAL_OVERRUN))
            {
                Program.errors += "Serial overrun, ";
            }
            if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_SERIAL_BUFFER_FULL))
            {
                Program.errors += "Serial RX buffer full, ";
            }
            if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_SERIAL_CRC))
            {
                Program.errors += "Serial CRC error, ";
            }
            if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_SERIAL_PROTOCOL))
            {
                Program.errors += "Serial protocol error, ";
            }
            if (1 == (1 & jrkVars.errorFlagBits >> (byte)jrkError.ERROR_SERIAL_TIMEOUT))
            {
                Program.errors += "Serial timeout error, ";
            }

            output = Program.Jrk1.getSerialNumber() + "," + Program.errors + "," + Program.current + "," + jrkVars.target + "," + servos[0].position + "," +
                     jrkVars.feedback + "," + jrkVars.scaledFeedback + "," + jrkVars.errorSum + "," + jrkVars.dutyCycleTarget + "," +
                     jrkVars.dutyCycle + "," + servos[0].speed + "," + servos[0].acceleration;

            //Print data to the file
            using (System.IO.StreamWriter file = new System.IO.StreamWriter(errorFileName, true))
            {
                file.WriteLine("{0}, {1}", degreeTracker, output);
            }

            //go to next spot
            //Set 0 motor to startTarget
            Program.usc.setTarget((byte)0, (ushort)startTarget);

            //Tracking values to make the loop go through even degree numbers
            startTargetTracker = startTargetTracker - 39.822;
            startTarget        = Convert.ToInt32(startTargetTracker);
            degreeTracker++;

            if (degreeTracker == 45)
            {
                loopTimer.Interval        = (1000) * (3);
                destinationTimer.Interval = (1000) * (3);
            }
            if (degreeTracker == 90)
            {
                loopTimer.Interval        = (1000) * (6);
                destinationTimer.Interval = (1000) * (6);
            }
            if (degreeTracker == 135)
            {
                loopTimer.Interval        = (1000) * (9);
                destinationTimer.Interval = (1000) * (9);
            }
            if (degreeTracker < 180)
            {
                notification         = "Now servicing the starting degree of " + degreeTracker;
                notificationBox.Text = notification;
                destinationTimer.Start();
            }
        }
Пример #4
0
        static void displayStatus(Jrk jrk)
        {
            Console.Write(
                "Serial number:       " + jrk.getSerialNumber() + "\n" +
                "Firmware version:    " + jrk.firmwareVersionString + "\n"
                );

            storeCurrentCalibration();

            jrkVariables vars = jrk.getVariables();

            Console.Write(
                "Variables:\n" +
                "  Input:             " + vars.input + "\n" +
                "  Target:            " + vars.target + "\n" +
                "  Feedback:          " + vars.feedback + "\n" +
                "  Scaled feedback:   " + vars.scaledFeedback + "\n" +
                "  Error:             " + (vars.scaledFeedback - vars.target) + "\n" +
                "  Integral:          " + vars.errorSum + "\n" +
                "  Duty cycle target: " + vars.dutyCycleTarget + "\n" +
                "  Duty cycle:        " + vars.dutyCycle + "\n" +
                "  Current (mA):      " + currentToMilliamps(vars.current, vars.dutyCycle) + "\n"
                );

            if (vars.errorFlagBits == 0)
            {
                Console.WriteLine("No errors.");
            }
            else
            {
                Console.WriteLine("Errors:");
                if (1 == (1 & vars.errorFlagBits >> (byte)jrkError.ERROR_AWAITING_COMMAND))
                {
                    Console.WriteLine("  Awaiting command");
                }
                if (1 == (1 & vars.errorFlagBits >> (byte)jrkError.ERROR_NO_POWER))
                {
                    Console.WriteLine("  No power");
                }
                if (1 == (1 & vars.errorFlagBits >> (byte)jrkError.ERROR_MOTOR_DRIVER))
                {
                    Console.WriteLine("  Motor driver error");
                }
                if (1 == (1 & vars.errorFlagBits >> (byte)jrkError.ERROR_INPUT_INVALID))
                {
                    Console.WriteLine("  Input invalid");
                }
                if (1 == (1 & vars.errorFlagBits >> (byte)jrkError.ERROR_INPUT_DISCONNECT))
                {
                    Console.WriteLine("  Input disconnect");
                }
                if (1 == (1 & vars.errorFlagBits >> (byte)jrkError.ERROR_FEEDBACK_DISCONNECT))
                {
                    Console.WriteLine("  Feedback disconnect");
                }
                if (1 == (1 & vars.errorFlagBits >> (byte)jrkError.ERROR_MAXIMUM_CURRENT_EXCEEDED))
                {
                    Console.WriteLine("  Max. current exceeded");
                }
                if (1 == (1 & vars.errorFlagBits >> (byte)jrkError.ERROR_SERIAL_SIGNAL))
                {
                    Console.WriteLine("  Serial signal error");
                }
                if (1 == (1 & vars.errorFlagBits >> (byte)jrkError.ERROR_SERIAL_OVERRUN))
                {
                    Console.WriteLine("  Serial overrun");
                }
                if (1 == (1 & vars.errorFlagBits >> (byte)jrkError.ERROR_SERIAL_BUFFER_FULL))
                {
                    Console.WriteLine("  Serial RX buffer full");
                }
                if (1 == (1 & vars.errorFlagBits >> (byte)jrkError.ERROR_SERIAL_CRC))
                {
                    Console.WriteLine("  Serial CRC error");
                }
                if (1 == (1 & vars.errorFlagBits >> (byte)jrkError.ERROR_SERIAL_PROTOCOL))
                {
                    Console.WriteLine("  Serial protocol error");
                }
                if (1 == (1 & vars.errorFlagBits >> (byte)jrkError.ERROR_SERIAL_TIMEOUT))
                {
                    Console.WriteLine("  Serial timeout error");
                }
            };
        }
Пример #5
0
        /// <summary>
        /// Call this function frequently, and it will take care of all the
        /// details printing the streamed variables from the Jrk.
        /// streamLineCount should be 0 before calling it for the first time.
        /// </summary>
        /// <param name="now">Should be approximately DateTime.Now.</param>
        static void streamPrintReading(DateTime now, jrkVariables vars)
        {
            try
            {
                uint time;

                if (streamLineCount == 0)
                {
                    // This will be the first line of the stream.

                    streamStartTime           = now;
                    streamTotalPidPeriodCount = 0;
                    time = 0;
                }
                else
                {
                    // This is not the first line of the stream.

                    if (streamLastPidPeriodCount == vars.pidPeriodCount)
                    {
                        // We already printed this set of variables so skip it.
                        return;
                    }

                    UInt16 increment = (UInt16)(vars.pidPeriodCount - streamLastPidPeriodCount);
                    streamTotalPidPeriodCount += increment;

                    time = (uint)(now - streamStartTime).TotalMilliseconds;
                }
                streamLastPidPeriodCount = vars.pidPeriodCount;

                // Print the reading.
                Console.WriteLine(streamFormat,
                                  time,
                                  streamTotalPidPeriodCount,
                                  vars.input,
                                  vars.target,
                                  vars.feedback,
                                  vars.scaledFeedback,
                                  vars.errorSum,
                                  vars.dutyCycleTarget,
                                  vars.dutyCycle,
                                  currentToMilliamps(vars.current, vars.dutyCycle),
                                  vars.errorFlagBits,
                                  vars.pidPeriodExceeded
                                  );

                // Keep track of how many liens we have printed.
                streamLineCount++;

                if (streamLineCountLimit.HasValue && streamLineCount >= streamLineCountLimit.Value)
                {
                    // We've printed all the lines that the user wanted, so quit.
                    Environment.Exit(0);
                }
            }
            catch (Exception exception)
            {
                printException(exception);
                Environment.Exit(3);
            }
        }
Пример #6
0
        static void streamVariables(Jrk jrk, Dictionary <String, String> opts)
        {
            // Determine what interval to use (the time between each reading).
            int interval = 20;

            if (opts.ContainsKey("interval"))
            {
                try
                {
                    interval = int.Parse(opts["interval"]);

                    if (interval < 0)
                    {
                        throw new Exception("Value must be a non-negative whole number.");
                    }
                }
                catch (Exception exception)
                {
                    throw new Exception("Invalid interval parameter \"" + opts["interval"] + "\".", exception);
                }
            }

            // Determine the output format.
            if (opts.ContainsKey("format"))
            {
                // The user specified the format string completely.
                streamFormat = opts["format"].Replace("\\t", "\t");
            }
            else
            {
                string separator = ",";

                if (opts.ContainsKey("separator"))
                {
                    // The user just specified the separator
                    separator = opts["separator"];

                    switch (separator)
                    {
                    case "space": separator = " "; break;

                    case "\\t":
                    case "tab": separator = "\t"; break;

                    case "comma": separator = ","; break;
                    }
                }

                if (separator == "\t")
                {
                    // If the separator is a tab, then we don't need to have padding spaced.
                    streamFormat = "{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}\t{9}\t{10}";
                }
                else
                {
                    // If the separator is something else, then we want padding to make each
                    // field be a fixed width.

                    streamFormat = "{0,6}" + separator +
                                   "{1,6}" + separator +
                                   "{2,4}" + separator +
                                   "{3,4}" + separator +
                                   "{4,4}" + separator +
                                   "{5,4}" + separator +
                                   "{6,6}" + separator +
                                   "{7,6}" + separator +
                                   "{8,4}" + separator +
                                   "{9,6}" + separator +
                                   "{10,4}";
                }
            }


            // Determine the limit.
            if (opts.ContainsKey("limit"))
            {
                try
                {
                    streamLineCountLimit = UInt32.Parse(opts["limit"]);
                }
                catch (Exception exception)
                {
                    throw new Exception("Invalid limit parameter \"" + opts["limit"] + "\".", exception);
                }
            }

            // Print the header line if the user wanted it
            if (!opts.ContainsKey("noheader"))
            {
                Console.WriteLine(streamFormat,
                                  "Time (ms)",
                                  "PID Period Count",
                                  "Input",
                                  "Target",
                                  "Feedback",
                                  "Scaled feedback",
                                  "Integral",
                                  "Duty cycle target",
                                  "Duty cycle",
                                  "Current (mA)",
                                  "Error code",
                                  "PID period exceeded");
            }

            // Prepare to process the current readings the Jrk will be sending us.
            storeCurrentCalibration();

            if (interval == 0)
            {
                // Interval is zero so the user just wants the data as fast as possible.
                while (true)
                {
                    streamPrintReading(DateTime.Now, jrk.getVariables());
                }
            }
            else
            {
                // The three timer classes provided by the .NET framework do not
                // provide accurate timing so instead we poll DateTime.Now.
                // This takes more CPU power than the timer method, but we try
                // to minimize the CPU use by sleeping between readings.

                DateTime now            = DateTime.Now;
                DateTime nextUpdateTime = now;
                while (true)
                {
                    if (nextUpdateTime <= now)
                    {
                        // Get the reading from the Jrk over USB (should take about .2 ms).
                        jrkVariables vars = jrk.getVariables();

                        streamPrintReading(now, vars);

                        while (nextUpdateTime <= DateTime.Now)
                        {
                            nextUpdateTime = nextUpdateTime.AddMilliseconds(interval);
                        }

                        // Conserve CPU power by sleeping
                        if (interval > 4 && !opts.ContainsKey("nosleep"))
                        {
                            Thread.Sleep(interval - 4);
                        }
                    }
                    now = DateTime.Now;
                }
            }
        }