📄 manual.c
字号:
//*****************************************************************************
//
// manual.c - Manual control of the table.
//
// Copyright (c) 2006-2007 Luminary Micro, Inc. All rights reserved.
//
// Software License Agreement
//
// Luminary Micro, Inc. (LMI) is supplying this software for use solely and
// exclusively on LMI's microcontroller products.
//
// The software is owned by LMI and/or its suppliers, and is protected under
// applicable copyright laws. All rights are reserved. Any use in violation
// of the foregoing restrictions may subject the user to criminal sanctions
// under applicable laws, as well as to civil liability for the breach of the
// terms and conditions of this license.
//
// THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
// OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
// LMI SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
// CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
//
// This is part of revision 220 of sw01246.
//
//*****************************************************************************
#include "hw_memmap.h"
#include "hw_types.h"
#include "gpio.h"
#include "sysctl.h"
#include "uart.h"
#include "draw.h"
#include "main.h"
#include "manual.h"
#include "table.h"
#include "tool.h"
#include "virtualtimer.h"
//*****************************************************************************
//
//! \page main_manual_intro Introduction
//!
//! A manual mode is provided for the CNC machine, where a simple user
//! interface over the UART provides direct control of the movements of the
//! machine. The speed, acceleration, and position of the table can be
//! specified, and then a movement performed. The tool power can also be
//! manually turned on and off.
//!
//! When a movement is made, the tool is first moved to the X/Y coordinate
//! specified, at the speed and acceleration provided. Once at the new
//! position, the tool is moved down to the specified Z position at a fixed
//! speed of 1200 steps per second and a fixed acceleration of 30,000 steps per
//! second^2. It will pause at that position for two seconds and then move
//! back to Z=0 at the same Z speed.
//!
//! Once called, manual mode does not return. Either the machine is operated
//! in manual mode or it is operated normally and manual mode is not available.
//! While in manual mode, the I2C commands from the user interface
//! microcontroller are still received and processed, though only the
//! diagnostic movement commands actually take effect.
//!
//! The following commands can be provided while in manual mode:
//!
//! - '0': Sets the speed of the movement in the X/Y plane. The speed can not
//! be set to zero (it would never move) and the maximum speed is
//! limited by the capabilities of the machine (though it is not limited
//! by the manual mode interface).
//!
//! - '1': Sets the acceleration of the movement in the X/Y plane. The
//! acceleration can not be set to zero (it would never move) and the
//! maximum acceleration is limited by the capabilities of the machine
//! (though it is not limited by the manual mode interface).
//!
//! - '2': Sets the new X coordinate value. The X coordinate values are
//! limited by the size of the CNC machine, though it must be a positive
//! value. The value is not limited by the manual mode interface
//! outside the requirement that the value be positive.
//!
//! - '3': Sets the new Y coordinate value. The Y coordinate values are
//! limited by the size of the CNC machine, though it must be a positive
//! value. The value is not limited by the manual mode interface
//! outside the requirement that the value be positive.
//!
//! - '4': Sets the new Z coordinate value. The Z coordinate values are
//! limited by the size of the CNC machine, though it must be a positive
//! value. The value is not limited by the manual mode interface
//! outside the requirement that the value be positive.
//!
//! - '5': Starts the movement to the specified position. Once running, the
//! movement can be aborted at any time by pressing any key.
//!
//! - '6': Turns on the power to the tool.
//!
//! - '7': Turns off the power to the tool.
//!
//! A menu is displayed on the UART that provides the current configuration of
//! the speed, acceleration, and position, along with the list of valid
//! commands that can be entered.
//!
//! The code for the manual mode interface is contained in
//! <tt>main_micro/manual.c</tt>, with <tt>main_micro/manual.h</tt> containing
//! the API definitions for use by the remainder of the application.
//
//*****************************************************************************
//*****************************************************************************
//
//! \defgroup main_manual_api Definitions
//! @{
//
//*****************************************************************************
//*****************************************************************************
//
//! Converts an integer to ASCII and sends it to the UART.
//!
//! \param lValue is the value to be displayed.
//!
//! This function is used to display an integer in human readable form (i.e.
//! base ten) on the UART. The input value is treated as a signed value;
//! negative values will be displayed with a preceeding "-" sign.
//!
//! \note This will not return until all of the characters have been sent to
//! the UART, which does not mean that they have all been transmitted.
//!
//! \return None.
//
//*****************************************************************************
static void
ManualSendValue(long lValue)
{
long lIdx;
//
// See if the value is negative.
//
if(lValue < 0)
{
//
// The value is negative, so print out the negative sign.
//
UARTCharPut(UART0_BASE, '-');
//
// Make the value be positive.
//
lValue = 0 - lValue;
}
//
// Loop over the possible digits in a 32-bit value (when converted to
// decimal).
//
for(lIdx = 1000000000; lIdx != 1; lIdx /= 10)
{
//
// Print out this digit only if the value requires this digit.
//
if(lValue >= lIdx)
{
UARTCharPut(UART0_BASE, '0' + ((lValue / lIdx) % 10));
}
}
//
// Print out the ones digit of the value. This is always done so that the
// value always has at least one digit representing it.
//
UARTCharPut(UART0_BASE, '0' + (lValue % 10));
}
//*****************************************************************************
//
//! Sends a string to the UART.
//!
//! \param pcString is a pointer to the string to be displayed.
//!
//! This function is used to send a string of characters to the UART.
//!
//! \note This will not return until all of the characters in the string have
//! been sent to the UART, which does not mean that they have all been
//! transmitted.
//!
//! \return None.
//
//*****************************************************************************
static void
ManualSendString(char *pcString)
{
//
// Loop while there are more characters in the string.
//
while(*pcString)
{
//
// Send this character to the UART.
//
UARTCharPut(UART0_BASE, *pcString++);
}
}
//*****************************************************************************
//
//! Reads an integer from the UART.
//!
//! This function reads an integer from the UART. Only positive integers can
//! be entered, and limited line editing is supported (i.e. the backspace key
//! can erase numbers that have been entered). Only digits received from the
//! UART will be echoed back; other characters (such as letters) will be
//! silently ignored.
//!
//! \return Returns the integer read from the UART.
//
//*****************************************************************************
static unsigned long
ManualGetValue(void)
{
unsigned long ulValue, ulCount;
char cChar;
//
// Set the value and count of digits to zero.
//
ulValue = 0;
ulCount = 0;
//
// Loop forever. This loop will be broken out of when the character is
// fully read.
//
while(1)
{
//
// Read a character from the UART.
//
cChar = UARTCharGet(UART0_BASE);
//
// See if the character read is a digit.
//
if((cChar >= '0') && (cChar <= '9'))
{
//
// Write the digit to the UART.
//
UARTCharPut(UART0_BASE, cChar);
//
// Add the digit to the value being read.
//
ulValue *= 10;
ulValue += cChar - '0';
//
// Increment the count of digits in the value.
//
ulCount++;
}
//
// See if the character read is a backspace and there are still some
// digits in the value read.
//
if((cChar == '\b') && (ulCount != 0))
{
//
// Erase the most recent digit from the UART.
//
ManualSendString("\b \b");
//
// Remove the most recent digit from the value.
//
ulValue /= 10;
//
// Decrement the count of digits in the value.
//
ulCount--;
}
//
// See if the character read is a carriage return or new line.
//
if((cChar == '\n') || (cChar == '\r'))
{
//
// Move the cursor to the beginning of the next line.
//
ManualSendString("\r\n");
//
// Return the value read.
//
return(ulValue);
}
}
}
//*****************************************************************************
//
//! Provides manual mode control of the CNC machine.
//!
//! This function provides simple control of the CNC machine via commands
//! entered via the UART.
//!
//! \return Never returns.
//
//*****************************************************************************
void
ManualMode(void)
{
unsigned long ulSpeed, ulAccel, ulX, ulY, ulZ, ulValue, ulStart;
char cChar;
//
// Enable the UART.
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
//
// Change the UART pins to peripheral function.
//
GPIODirModeSet(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1, GPIO_DIR_MODE_HW);
//
// Configure the UART for 115,200, 8-N-1 operation.
//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -