?? demo.c
字號:
//*****************************************************************************
//
// demo.c - CNC demonstration routines.
// demo.c - CNC 示例程序
//
// 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 "demo.h"
#include "draw.h"
#include "i2c_slave.h"
#include "images.h"
#include "main.h"
#include "table.h"
#include "tool.h"
#include "virtualtimer.h"
//*****************************************************************************
//
//! \page main_demo_intro Introduction
//!
//! The demonstration routines are a set of examples that utilize the CNC
//! machine to actually draw something interesting. There are six
//! demonstrations provided:
//!
//! - The first demonstration draws a logo and text stacked one on top of the
//! other.
//!
//! - The second demonstration draws a logo and text side by side with an
//! octagonal box surrounding both. This is the only demonstration that is
//! really designed for use on wood with a router; the end result can be used
//! as a name plate (on a desk or on an office door).
//!
//! - The third demonstration draws a steer head.
//!
//! - The fourth demonstration draws one side of a printed circuit board.
//!
//! - The fifth demonstration draws a football (soccer) pitch.
//!
//! - The sixth demonstration draws a map of the world.
//!
//! The code for the demonstration routines is contained in
//! <tt>main_micro/demo.c</tt>, with <tt>main_micro/demo.h</tt> containing the
//! API definitions for use by the remainder of the application.
//
//*****************************************************************************
//*****************************************************************************
//
//! \defgroup main_demo_api Definitions
//! @{
//
//*****************************************************************************
//*****************************************************************************
//
//! The X coordinate of the corner of the workpiece when using the pen, based
//! on the table's mounting mechanism for paper material. This is the absolute
//! corner of the workpiece; for a non-zero diameter pen (i.e. all pens!), this
//! value must be offset by the radius of the pen to place the entire pen tip
//! on the workpiece (and therefore avoid drawing off the paper and possibly
//! colliding with the paper holding mechanism).
//
//*****************************************************************************
#define PEN_CORNER_X 2500
//*****************************************************************************
//
//! The Y coordinate of the corner of the workpiece when using the pen, based
//! on the table's mounting mechanism for paper material. This is the absolute
//! corner of the workpiece; for a non-zero diameter pen (i.e. all pens!), this
//! value must be offset by the radius of the pen to place the entire pen tip
//! on the workpiece (and therefore avoid drawing off the paper and possibly
//! colliding with the paper holding mechanism).
//
//*****************************************************************************
#define PEN_CORNER_Y 4800
//*****************************************************************************
//
//! The depth for the pen when traversing the table. If the pen is on the
//! drawing surface and needs to be moved without drawing, this is the depth to
//! which the pen is moved before the traversal.
//
//*****************************************************************************
#define PEN_TRAVERSE 5200
//*****************************************************************************
//
//! The depth from the pen traversal depth when drawing on the table. By
//! moving the pen to the traversal depth plus the drawing depth, the pen will
//! be on the table and therefore drawing lines.
//
//*****************************************************************************
#define PEN_DEPTH 800
//*****************************************************************************
//
//! The X coordinate of the corner of the workpiece when using the router,
//! based on the table's mounting mechanism for wood material. This is the
//! absolute corner of the workpiece; for a non-zero diameter router bit (i.e.
//! all router bits!), this value must be offset by the radius of the router
//! bit to place the entire bit on the workpiece (and therefore avoid routing
//! the holding mechanism).
//
//*****************************************************************************
#define ROUTER_CORNER_X 625
//*****************************************************************************
//
//! The X coordinate of the corner of the workpiece when using the router,
//! based on the table's mounting mechanism for wood material. This is the
//! absolute corner of the workpiece; for a non-zero diameter router bit (i.e.
//! all router bits!), this value must be offset by the radius of the router
//! bit to place the entire bit on the workpiece (and therefore avoid routing
//! the holding mechanism).
//
//*****************************************************************************
#define ROUTER_CORNER_Y 5885
//*****************************************************************************
//
//! The depth for the router when traversing the table. If the router is on
//! the drawing surface and needs to be moved without drawing, this is the
//! depth to which the router is moved before the traversal.
//
//*****************************************************************************
#define ROUTER_TRAVERSE (5300 - 360)
//*****************************************************************************
//
//! The incremental depth of each extra routing pass. This is how much further
//! down the router is moved for each subsequent pass of the design, causing
//! the design to be cut deeper into the surface of the wood.
//
//*****************************************************************************
#define ROUTER_DEPTH_INCREMENT 90
//*****************************************************************************
//
//! The depth from the router traversal depth when drawing on the table. By
//! moving the router to the traversal depth plus the drawing depth, the router
//! will be on the table and therefore drawing lines.
//
//*****************************************************************************
#define ROUTER_DEPTH (360 + ROUTER_DEPTH_INCREMENT)
//*****************************************************************************
//
//! The number of steps per inch in the X and Y axes.
//
//*****************************************************************************
#define STEPS 800
//*****************************************************************************
//
//! Convert from inches to steps.
//!
//! \param w is the whole number of inches.
//! \param f is the fraction number of inches, in thousandths of an inch.
//!
//! This macro converts a value specified as inches and thousandths of an inch
//! into the number of steps. This allows specification of distances in inches
//! (which is much more natural than steps) and allows the steps per inches to
//! be changed (either with a different lead screw or a different stepper
//! motor) without having to change every distance reference.
//!
//! \return The number of steps in the specified distance.
//
//*****************************************************************************
#define INCHES(w, f) ((STEPS * (w)) + ((STEPS * (f)) / 1000))
//*****************************************************************************
//
//! An array used to construct an image to be drawn on the table. This is used
//! by the second demonstration for the border around the text and logo.
//
//*****************************************************************************
static unsigned short g_pusBorder[21];
//*****************************************************************************
//
//! Performs generic tool setup for a demonstration.
//!
//! \param pulX is a pointer to the variable to be filled in with the X
//! coordinate of the lower left corner of the workpiece for this tool.
//! \param pulY is a pointer to the variable to be filled in with the Y
//! coordinate of the lower left corner of the workpiece for this tool.
//! \param pulZ is a pointer to the variable to be filled in with the traversal
//! depth for this tool.
//! \param pulDepth is a pointer to the variable to be filled in with the depth
//! below the traversal depth.
//! \param pulIterations is a pointer to the variable to be filled in with the
//! number of iterations of the design to be performed.
//!
//! This function will perform common tool setup for a demonstration. The
//! tool depths and drawing iteration are determined, and configures the
//! drawing routines with the required speed for drawing.
//!
//! \return None.
//
//*****************************************************************************
static void
DemoSetupTool(unsigned long *pulX, unsigned long *pulY, unsigned long *pulZ,
unsigned long *pulDepth, unsigned long *pulIterations)
{
//
// See if the pen is the selected tool.
//
if(g_ulTool == 0x00)
{
//
// Set the workpiece corner based on the pen tool.
//
*pulX = PEN_CORNER_X;
*pulY = PEN_CORNER_Y;
//
// Set the traversal depth based on the pen tool.
//
*pulZ = PEN_TRAVERSE;
//
// Set the drawing depth based on the pen tool.
//
*pulDepth = PEN_DEPTH;
//
// Only do a single iteration with the pen.
//
*pulIterations = 1;
//
// Set the drawing speed.
//
DrawSetDrawSpeed(2400, 30000);
//
// Set the traversal speed.
//
DrawSetTraverseSpeed(2400, 30000);
//
// Set the Z axis speed.
//
DrawSetZSpeed(1200, 30000);
}
//
// Otherwise, the router is the selected tool.
//
else
{
//
// Set the workpiece corner based on the router tool.
//
*pulX = ROUTER_CORNER_X;
*pulY = ROUTER_CORNER_Y;
//
// Set the traversal depth based on the router tool.
//
*pulZ = ROUTER_TRAVERSE;
//
// Set the drawing depth based on the router tool.
//
*pulDepth = ROUTER_DEPTH;
//
// Select the number of iterations based on the requested depth.
//
*pulIterations = (g_ulTool & 0x0f) + 1;
//
// Set the drawing speed.
//
DrawSetDrawSpeed(300, 30000);
//
// Set the traversal speed.
//
DrawSetTraverseSpeed(2400, 30000);
//
// Set the Z axis speed.
//
DrawSetZSpeed(1200, 30000);
}
}
//*****************************************************************************
//
//! Delays for a period of time.
//!
//! \param ulMilliseconds is the number of milliseconds to delay.
//!
//! This function delays for a given period of time. The count of milliseconds
//! to delay can not exceed 2^32 / (system clock / 1000) or the delay will be
//! much shorter than expected; in practice this isn't typically a problem
//! since this equates to 85.899 seconds for a 50 MHz processor clock.
//!
//! \return None.
//
//*****************************************************************************
static void
DemoDelay(unsigned long ulMilliseconds)
{
unsigned long ulNow;
//
// Get the present time.
//
ulNow = VirtualTimeGet();
//
// Loop until the given time has passed.
//
while((VirtualTimeGet() - ulNow) <
((g_ulSysClock / 1000) * ulMilliseconds))
{
}
}
//*****************************************************************************
//
//! Performs the first CNC demonstration.
//!
//! This demonstration of the CNC machine draws an optional logo and the
//! supplied string stacked on top of each other. It is intended to be used
//! with a pen and a piece of paper approximately five inches (12.7 cm) square.
//! The text is drawn a quarter inch (0.6 cm) tall, and the logo is drawn one
//! inch (2.54 cm) tall.
//!
//! \return None.
//
//*****************************************************************************
void
Demo1(void)
{
unsigned long ulX, ulY, ulZ, ulDepth, ulIterations, ulXS, ulYS;
long lIconHeight, lIconWidth, lStringWidth, lYMin, lYMax;
//
// Setup the tool for this demo.
//
DemoSetupTool(&ulX, &ulY, &ulZ, &ulDepth, &ulIterations);
//
// Get the extents of the name string.
//
if(g_pcNameString[0] != '\0')
{
DrawGetStringSize(g_pcNameString, INCHES(0, 250), &lStringWidth,
&lYMin, &lYMax);
}
else
{
lStringWidth = 0;
lYMin = 0;
lYMax = 0;
}
//
// Get the size of the icon.
//
if(g_ulIcons & 0x01)
{
lIconWidth = DrawGetImageWidth(g_pusLMI, INCHES(1, 000));
lIconHeight = INCHES(1, 000);
}
else if(g_ulIcons & 0x02)
{
lIconWidth = DrawGetImageWidth(g_pusARM, INCHES(1, 000));
lIconHeight = INCHES(1, 000);
}
else
{
lIconWidth = INCHES(0, 000);
lIconHeight = INCHES(0, 000);
}
//
// If there is a name string and an icon, then add the 1/4 inch (0.6 cm)
// gap between the two to the height of the string.
//
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -