📄 draw.c
字号:
//*****************************************************************************
//
// draw.c - Routines for drawing shapes on the CNC machine.
//
// 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_types.h"
#include "draw.h"
#include "table.h"
#include "vectorfont.h"
//*****************************************************************************
//
//! \page main_draw_intro Introduction
//!
//! The drawing interface provides a means of rendering text using a Hershey
//! Simplex Roman font and rendering vector images. The text and images can
//! be drawn at arbitrary sizes; the height at which they are to be drawn is
//! specified and all font/image data is scaled as appropriate to make the
//! drawing the specified height.
//!
//! When drawing, three different speeds are applied. The first is the drawing
//! speed, which is the speed of the tool when in contact with the work piece.
//! This speed will vary depending upon the tool and work piece in use. For
//! example, when using a pen as the tool, the drawing speed can be the maximum
//! speed obtainable with the machine. On the other hand, when using a router
//! as the tool, the drawing speed will be much slower. Also, when using a
//! router, the drawing speed will be faster for a soft wood (such as pine)
//! than it will be for a hard wood (such as mahogany).
//!
//! The second speed is the traversal speed, which is the speed of the tool
//! when not in contact with the work piece. Typically, this will be the
//! maximum speed obtainable with the machine, though it may be slower because
//! of the weight of the tool itself. Since the tool is not in contact with
//! the work piece, the speed of traversal isn't slowed down by the
//! characteristics of the tool and work piece.
//!
//! The third speed is the Z axis speed, which is the speed at which the tool
//! is raised and lowered. Typically, this will also be the maximum speed
//! obtainable with the machine, though it may be slower because of the weight
//! of the tool itself and the interaction of the tool with the work piece as
//! the tool is being lowered (i.e. the plunging action of a spinning router
//! bit into a piece of wood).
//!
//! By the use of arbitrary drawing start and stop routines, multiple calls to
//! the text and image rendering functions can be grouped together as a single
//! drawing action. This drawing action can therefore be aborted midway
//! through, for example as a result of a user request to stop the machine.
//!
//! The code for the drawing routines is contained in
//! <tt>main_micro/draw.c</tt>, with <tt>main_micro/draw.h</tt> containing the
//! API definitions for use by the remainder of the application.
//
//*****************************************************************************
//*****************************************************************************
//
//! \defgroup main_draw_api Definitions
//! @{
//
//*****************************************************************************
//*****************************************************************************
//
//! The speed of the tool across the work piece when drawing (i.e. when the
//! tool is contacting the work piece).
//
//*****************************************************************************
static unsigned long g_ulDrawSpeed;
//*****************************************************************************
//
//! The acceleration of the tool across the work piece when drawing (i.e. when
//! the tool is contacting the work piece). This acceleration is used when
//! going from a stop up to drawing speed, and double this acceleration is used
//! when going from speed to a stop (i.e. accelerate slower when speeding up
//! since friction must be overcome and faster when slowing down since friction
//! will help).
//
//*****************************************************************************
static unsigned long g_ulDrawAccel;
//*****************************************************************************
//
//! The speed of the tool across the work piece when traversing (i.e. when the
//! tool is raised above the work piece).
//
//*****************************************************************************
static unsigned long g_ulTraverseSpeed;
//*****************************************************************************
//
//! The acceleration of the tool across the work piece when traversing (i.e.
//! when the tool is raised above the work piece). This acceleration is used
//! when going from a stop to traversal speed, and double this acceleration is
//! used when going from speed to a stop (i.e. accelerate slower when speeding
//! up since friction must be overcome and faster when slowing down since
//! friction will help).
//
//*****************************************************************************
static unsigned long g_ulTraverseAccel;
//*****************************************************************************
//
//! The speed of the tool along the Z axis (i.e. when the tool is being raised
//! or lowered).
//
//*****************************************************************************
static unsigned long g_ulZSpeed;
//*****************************************************************************
//
//! The acceleration of the tool along the Z axis (i.e. when the tool is being
//! raised or lowered). This acceleration is used when going from a stop to
//! Z axis speed, and double this acceleration is used when going from speed to
//! a stop (i.e. accelerate slower when speeding up since friction must be
//! overcome and faster when slowing down since friction will help).
//
//*****************************************************************************
static unsigned long g_ulZAccel;
//*****************************************************************************
//
//! A set of flags that control the drawing routines; contains the
//! #DRAW_FLAG_DRAWING flag.
//
//*****************************************************************************
static unsigned long g_ulDrawFlags;
//*****************************************************************************
//
//! The bit number in #g_ulDrawFlags of the flag that is set when there is a
//! drawing in progress.
//
//*****************************************************************************
#define DRAW_FLAG_DRAWING 0
//*****************************************************************************
//
//! Start a drawing.
//!
//! This is used to indicate that a set of drawing actions are about to take
//! place. The actually drawing routines will not run to completion if this
//! is not called first; DrawStart() and DrawStop() are used as a bracket
//! around a set of drawing actions and a means of aborting them before they
//! are complete.
//!
//! \return None.
//
//*****************************************************************************
void
DrawStart(void)
{
//
// Indicate that a drawing is in progress.
//
HWREGBITW(&g_ulDrawFlags, DRAW_FLAG_DRAWING) = 1;
}
//*****************************************************************************
//
//! Stop a drawing.
//!
//! This is used to indicate that a set of drawing actions are complete. If
//! a drawing routines is in progress when this is called, the drawing will be
//! aborted and the tool left in its present location.
//!
//! \return None.
//
//*****************************************************************************
void
DrawStop(void)
{
//
// Indicate that the drawing is done (or should be aborted).
//
HWREGBITW(&g_ulDrawFlags, DRAW_FLAG_DRAWING) = 0;
}
//*****************************************************************************
//
//! Determines if a drawing is in progress.
//!
//! This function determines whether or not a set of drawing actions are being
//! performed.
//!
//! \return Returns \b true if a drawing is in progress and \b false otherwise.
//
//*****************************************************************************
tBoolean
DrawIsDrawing(void)
{
//
// A drawing is in progress if the corresponding flag is set.
//
return(HWREGBITW(&g_ulDrawFlags, DRAW_FLAG_DRAWING) == 1 ? true : false);
}
//*****************************************************************************
//
//! Sets the drawing speed.
//!
//! \param ulSpeed is the maximum number of steps per second of the tool along
//! its path of movement.
//! \param ulAccel is the acceleration, in steps per second^2, of the tool
//! along its path of movement.
//!
//! This function sets the maximum speed of motion when drawing (i.e. when the
//! tool is in contact with the work piece). The given acceleration is used
//! to accelerate from a stop to the maximum speed, and double the acceleration
//! is used to accelerate from maximum speed to a stop (i.e. start slower since
//! friction must be overcome and stop faster since friction will help).
//!
//! The speed and acceleration are specified as the speed of the tool across
//! the work piece; the actual speed and acceleration of the gantry will be
//! scaled to achieve the desired speed and acceleration along the motion's
//! diagonal.
//!
//! \return None.
//
//*****************************************************************************
void
DrawSetDrawSpeed(unsigned long ulSpeed, unsigned long ulAccel)
{
//
// Save the drawing speed and acceleration.
//
g_ulDrawSpeed = ulSpeed;
g_ulDrawAccel = ulAccel;
}
//*****************************************************************************
//
//! Sets the traverse speed.
//!
//! \param ulSpeed is the maximum number of steps per second of the tool along
//! its path of movement.
//! \param ulAccel is the acceleration, in steps per second^2, of the tool
//! along its path of movement.
//!
//! This function sets the maximum speed of motion when not drawing (i.e. when
//! the tool is not in contact with the work piece). The given acceleration
//! is used to accelerate from a stop to the maximum speed, and double the
//! acceleration is used to accelerate from maximum speed to a stop (i.e. start
//! slower since friction must be overcome and stop faster since friction will
//! help).
//!
//! The speed and acceleration are specified as the speed of the tool across
//! the work piece; the actual speed and acceleration of the gantry will be
//! scaled to achieve the desired speed and acceleration along the motion's
//! diagonal.
//!
//! \return None.
//
//*****************************************************************************
void
DrawSetTraverseSpeed(unsigned long ulSpeed, unsigned long ulAccel)
{
//
// Save the traverse speed and acceleration.
//
g_ulTraverseSpeed = ulSpeed;
g_ulTraverseAccel = ulAccel;
}
//*****************************************************************************
//
//! Set the tool movement speed.
//!
//! \param ulSpeed is the maximum number of steps per second along the tool (or
//! Z) axis.
//! \param ulAccel is the accleration, in steps per second^2, of the motion
//! along the Z axis.
//!
//! This function sets the maximum speed of motion along the tool axis (i.e.
//! moving the tool up and down). The given acceleration is used to accelerate
//! from a stop to the maximum speed, and double the acceleration is used to
//! accelerate from maximum speed to a stop (i.e. start slower since friction
//! must be overcome and stop faster since friction will help).
//!
//! \return None.
//
//*****************************************************************************
void
DrawSetZSpeed(unsigned long ulSpeed, unsigned long ulAccel)
{
//
// Save the Z speed and acceleration.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -