This is the firmware for the LaOS - Laser Open Source project. You can use it to drive a laser cutter. For hardware and more information, look at our wiki: http://wiki.laoslaser.org

Dependencies:   EthernetNetIf mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers global.cpp Source File

global.cpp

00001 /*
00002  * global.cpp
00003  * Read global configuration from file
00004  *
00005  * Copyright (c) 2011 Peter Brier
00006  *
00007  *   This file is part of the LaOS project (see: http://wiki.protospace.nl/index.php/LaOS)
00008  *
00009  *   LaOS is free software: you can redistribute it and/or modify
00010  *   it under the terms of the GNU General Public License as published by
00011  *   the Free Software Foundation, either version 3 of the License, or
00012  *   (at your option) any later version.
00013  *
00014  *   LaOS is distributed in the hope that it will be useful,
00015  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  *   GNU General Public License for more details.
00018  *
00019  *   You should have received a copy of the GNU General Public License
00020  *   along with LaOS.  If not, see <http://www.gnu.org/licenses/>.
00021  * 
00022  */
00023 #include "global.h"
00024 #include "ConfigFile.h"
00025 
00026 
00027 
00028 /**
00029 *** Return a IpAddress, from a string in the format: ppp.qqq.rrr.sss
00030 **/
00031 void IpParse(char *a, int i[]) 
00032 {
00033     int n = 0, j;
00034     char c[4];
00035 
00036     i[0] = i[1] = i[2] = i[3] =0;
00037     for (n=0; n<4; n++) {
00038         while (*a && (*a < '0' || *a > '9'))
00039             a++;
00040         j = 0;
00041         while (*a && *a >= '0' && *a <= '9') 
00042         {
00043             if ( j<3 )
00044                 c[j++] = *a;
00045             a++;
00046         }
00047         c[j] = 0;
00048         i[n] = atoi(c);
00049     }
00050 }
00051  
00052  
00053 /**
00054 *** Global config
00055 *** Config settings into global Config struct
00056 **/
00057 GlobalConfig::GlobalConfig(char *filename)
00058 {
00059    char val[32];
00060    printf("\r\nOpen config file: '%s'\r\n", filename);
00061    ConfigFile cfg(filename);
00062     if ( !cfg.IsOpen() ) 
00063     {
00064       printf("File does not exists. Using defaults\n");
00065     }
00066     
00067     // IP settings
00068     cfg.Value("net.ip", val, sizeof(val), "192.168.0.111");
00069     IpParse(val, ip);
00070     cfg.Value("net.mask", val, sizeof(val), "255.255.255.0");
00071     IpParse(val, nm);
00072     cfg.Value("net.gateway", val, sizeof(val), "192.168.0.1");
00073     IpParse(val, gw);
00074     cfg.Value("net.dns", val, sizeof(val), "192.168.0.1");
00075     IpParse(val, dns);
00076     cfg.Value("net.port", &port, 69);
00077     cfg.Value("net.dhcp", &dhcp, 0);
00078 
00079     // features
00080     cfg.Value("sys.autohome", &autohome, 0);
00081     cfg.Value("sys.autozhome", &autozhome, 0);
00082     cfg.Value("sys.nodisplay", &nodisplay, 1);
00083     cfg.Value("sys.i2cbaud", &i2cbaud, 9600);
00084     cfg.Value("sys.cleandir", &cleandir, 1);
00085     
00086     // Laser
00087     cfg.Value("laser.enable", &lenable, 1); // laser enable polarity [0/1]
00088     cfg.Value("laser.on", &lon, 1);         // laser on polarity [0/1]
00089     cfg.Value("laser.pwm.min", &pwmmin, 0); // pwm at minimum power [0..100]
00090     cfg.Value("laser.pwm.max", &pwmmax, 0); // pwm at maximum power [0..100]
00091     cfg.Value("laser.pwm.freq", &pwmfreq, 20000); // pwm frequency [Hz]  
00092     
00093     // rest position (after homing)
00094     cfg.Value("x.rest", &xrest, 0);
00095     cfg.Value("y.rest", &yrest, 0);
00096     cfg.Value("z.rest", &zrest, 0);
00097     cfg.Value("e.rest", &erest, 0);
00098  // (homing) direction
00099     cfg.Value("x.homedir", &xhomedir, 0);
00100     cfg.Value("y.homedir", &yhomedir, 0);
00101     cfg.Value("z.homedir", &zhomedir, 0);
00102     cfg.Value("e.homedir", &ehomedir, 0);
00103 
00104     cfg.Value("x.invert", &xinv, 0);
00105     cfg.Value("y.invert", &yinv, 0);
00106     cfg.Value("z.invert", &zinv, 0);
00107     cfg.Value("e.invert", &einv, 0);
00108 
00109 
00110     // (homing)sensor polarity
00111     cfg.Value("x.pol", &xpol, 0);
00112     cfg.Value("y.pol", &ypol, 0);
00113     cfg.Value("z.pol", &zpol, 0);
00114     cfg.Value("e.pol", &epol, 0);
00115     
00116     // Scaling [steps/meter]
00117     cfg.Value("x.scale", &xscale, 200000);
00118     cfg.Value("y.scale", &yscale, 200000);
00119     cfg.Value("z.scale", &zscale, 200000);
00120     cfg.Value("e.scale", &escale, 200000);
00121    
00122     // max axis speed [mm/sec]
00123     cfg.Value("x.speed", &xspeed, 100);
00124     cfg.Value("y.speed", &yspeed, 100);
00125     cfg.Value("z.speed", &zspeed, 100);
00126     cfg.Value("e.speed", &espeed, 100);
00127    
00128     // home positions [um]
00129     cfg.Value("x.home", &xhome, 0);
00130     cfg.Value("y.home", &yhome, 0);
00131     cfg.Value("z.home", &zhome, 100000);
00132     cfg.Value("e.home", &ehome, 0);
00133      
00134     // min and max [um]
00135     cfg.Value("x.max", &xmax, 1E6);
00136     cfg.Value("y.max", &ymax, 1E6);
00137     cfg.Value("z.max", &zmax, 200000);
00138     cfg.Value("e.max", &emax, 1E6); 
00139     cfg.Value("x.min", &xmin, 0); 
00140     cfg.Value("y.min", &ymin, 0); 
00141     cfg.Value("z.min", &zmin, 0);
00142     cfg.Value("e.min", &emin, 0); 
00143         
00144     // motion settings: enable output state    
00145     cfg.Value("motion.homespeed", &homespeed, 10); // speed during homing [mm/sec]     
00146     cfg.Value("motion.speed", &speed, 100);   // max speed [mm/sec] 
00147     cfg.Value("motion.accel", &accel, 100); // accelleration [mm/sec2] 
00148     cfg.Value("motion.enable", &enable, 0); // enable output polarity [0/1]
00149     cfg.Value("motion.tolerance", &tolerance, 50); // cornering tolerance [1/1000 units]     
00150 }
00151