Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
lissajous.cpp
00001 #include "mbed.h" 00002 //#include "rtos.h" 00003 #include "MODSERIAL.h" 00004 #include "cnc.h" 00005 extern MODSERIAL pc; 00006 //extern Serial pc; 00007 extern void move_to_XYZ (struct pirbufgrain & ins) ; 00008 /* 00009 This file contains one function: 00010 void lissajous () ; 00011 The purpose is to replicate a list of XY coordinates produced by a G Code programme written to run on Mach3 software 00012 to be used to set NCOs in sequence to prove this simple code running on a 'mbed' or 'Freescale KL25Z' 00013 does correctly drive the Sieg KX3 CNC mill, just the same as using the pc / Mach3 setup. 00014 00015 Thus far we have proved only that both finish at the same point (give or take a few microns) 00016 */ 00017 //bool liss_active = false; // global flag used to prevent running more than once at a time 00018 00019 void lissajous (fl_typ feed_rate) { 00020 const fl_typ PI = 4.0 * atan(1.0), //3.142ish but more accurate 00021 Deg2Rad = PI / 180.0, // degrees to radian conversion factor 00022 MaxX = 40.0, // Plot size X to move +/- MaxX 00023 MaxY = 25.0, // Plot size Y to move +/- MaxY 00024 StartAngDegX = 0.0, 00025 StartAngDegY = 10.0, 00026 FreqRatio = 0.255; 00027 const int StepsPerRevX = 100, 00028 NumofXCycles = 16; 00029 const fl_typ AngleStepX = (2.0 * PI / StepsPerRevX), 00030 AngleStepY = AngleStepX * FreqRatio; 00031 00032 //void lissajous (void const * arg_string) { 00033 struct pirbufgrain Coords; 00034 fl_typ AngleX = StartAngDegX * Deg2Rad, 00035 AngleY = StartAngDegY * Deg2Rad; 00036 00037 // pc.printf("In lissajous func, Loading Lissajous\r\n"); 00038 // while (1) { 00039 // while (!liss_active) // Other code to activate 00040 // osThreadYield(); 00041 // liss_active = true; // this hapens in activating code 00042 pc.printf("In lissajous func, Starting Lissajous, has been activated\r\n"); 00043 Coords.x = 0.0; 00044 Coords.y = 0.0; 00045 Coords.z = 12.7; 00046 Coords.f_rate = feed_rate; 00047 move_to_XYZ (Coords); 00048 Coords.x = MaxX * cos(AngleX); // Coordinates of start position 00049 Coords.y = MaxY * sin(AngleY); // assembled into packet for motion controller 00050 move_to_XYZ (Coords); 00051 Coords.z = 0.0; 00052 move_to_XYZ (Coords); 00053 00054 for (int i = 0; i < NumofXCycles; i++) { // Outer loop 'NumofXCycles' times 00055 for (int j = 0; j < StepsPerRevX; j++) { // Inner loop 'StepsPerRevX' times 00056 AngleX += AngleStepX; 00057 AngleY += AngleStepY; 00058 Coords.x = MaxX * cos(AngleX); 00059 Coords.y = MaxY * sin(AngleY); 00060 move_to_XYZ (Coords); 00061 // osThreadYield(); 00062 } 00063 pc.printf("liss cyc %d\r\n", i); 00064 } 00065 Coords.z = 100.0; 00066 move_to_XYZ (Coords); 00067 Coords.x = 0.0; 00068 Coords.y = 0.0; 00069 move_to_XYZ (Coords); 00070 00071 pc.printf("Lissajous finish point X%f, Y%f\r\n", Coords.x, Coords.y); 00072 // liss_active = false; 00073 pc.printf("Leaving liss\r\n"); 00074 // osThreadYield(); // terminate would be better here 00075 // } // end of while(1) 00076 } 00077 00078 /* 00079 The complete Mach3 G Code programme listing "lissajous.txt" follows :- 00080 */ 00081 00082 /* 00083 ; This Section to put machine into known, safe state 00084 M5 ; Stop spindle 00085 G17 ; Select XY plane 00086 G21 ; Units are mm 00087 G40 ; Cancel cutter radius compensation 00088 G49 ; Cancel tool length offset 00089 G61 ; Exact stop 00090 G50 ; Reset all scale factors to 1.0 00091 G90 ; Absolute distance mode 00092 G94 ; Feed mm per minute mode - as mm selected above by G21 00093 ; Title: Lissajous Pattern Generator 2014 00094 ; Programme Name "lissajous.txt" 00095 ; Author: Jon Freeman 00096 ; Date: Feb 2014 00097 00098 ; Demo code used to demonstrate Freescale FRDM-KL25Z computer board 00099 ; driving a Sieg KX3 CNC mill without PC, and without Mach3 !! 00100 00101 ; _____________________________________________ 00102 ; Put user alterable parameter values in this section 00103 ; User is invited to alter the 6 parameters in this section. 00104 00105 #10 = 6.40 ; Max 'X' excursion 00106 #11 = 3.20 ; Max 'Y' excursion 00107 #12 = 0.0 ; Start angle of 'X' 00108 #13 = 10.0 ; Start angle of 'Y' 00109 #14 = 0.254 ; Frequency ratio of X and Y signals 00110 #15 = 100 ; Int Steps per 2PI of X 00111 #16 = 16 ; Int Number of whole cycles of 'X' 00112 ; 00113 ; Programme starts here 00114 00115 #50 = [#10 * cos[#12]] ;Start X coord 00116 #51 = [#11 * sin[#13]] ;Start Y coord 00117 #52 = [360.0 / #15] ;Angle step X 00118 #53 = [#52 * #14] ;Angle step Y 00119 G0 X#50 Y#51 00120 M98 P 1000 L #16 ;Execute subroutine 'Numof X Cycles' times 00121 M5 M30 ; Stop, end and rewind 00122 00123 O 1000 ; Subroutine executed once per complete turn of 'X' 00124 M98 P 2000 L #15 ;Execute the subroutine and repeat 'Steps per Rev' times 00125 M99 ; Return 00126 00127 O 2000 ; Subroutine executed 'Numof X Cycles' * 'Steps per Rev' times 00128 #12 = [#12 + #52] ; Update X angle 00129 #13 = [#13 + #53] ; Update X angle 00130 #50 = [#10 * cos[#12]] ;Update X coord 00131 #51 = [#11 * sin[#13]] ;Update Y coord 00132 G1 X#50 Y#51 00133 M99 ; Return 00134 */ 00135
Generated on Sat Jul 16 2022 01:39:30 by
1.7.2