Show Posts
Pages: 1 2 3 [4] 5 6 ... 20
46  Forum 2005-2010 (read only) / Syntax & Programs / Re: ideas for parsing hpgl code? on: October 19, 2010, 05:08:58 pm
Quote
In the latest versions of the arduino IDE there is a string handling function that can form strings from inputs, then parce them in various ways.

Thanks - that's helpful (I realize it is not as fast as other methods but I can make progress, etc.)

Once I pull out the x + y as Strings, is there an easy way to convert them to integers?

Code:
void setup()
{
  Serial.begin(9600);
}

void loop()
{
  String scratchpad = "PD3450.0,-2202.0";
  String cmd = scratchpad.substring(0, 2);

  Serial.println("--------------");
  Serial.println(cmd);

  int len = scratchpad.length();
  int i = scratchpad.indexOf(",");

  String x = scratchpad.substring(2, i);
  String y = scratchpad.substring(i + 1, len);

  Serial.print("x: ");
  Serial.println(x);
  Serial.print("y: ");
  Serial.println(y);

  delay(2000);
}
47  Forum 2005-2010 (read only) / Syntax & Programs / ideas for parsing hpgl code? on: October 19, 2010, 01:57:56 pm
Hi, I need to write a parser for hpgl code received over Serial. I've looked around for examples and the ones I've found are over my head and either can't compile them or can't fix the errors. Sometimes (most times?) trying to reuse code that one doesn't understand is not very useful for either getting the project done or learning.

So - I am thinking of just writing my own. HPGL is a simple semi-colon delimited command format: PD3206,1566;

Anyone have any tips on how to break out the alpha cmd (PD) and the x, y ints?

--Roy

Here is what I've been trying (without success so far):
Code:
#include <avr/pgmspace.h>

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  char* scratchpad;
  scratchpad = "PD3450.0,2202.0";
  char s[10];
  float f;

  int n = sscanf_P(scratchpad,PSTR("%f %s"),&f,&s);

  Serial.println("--------------");
  Serial.print("n ");
  Serial.println(n);
  Serial.print("f ");
  Serial.println(f);
  Serial.print("s ");
  Serial.println(s);

  delay(2000);
}

48  Forum 2005-2010 (read only) / Syntax & Programs / Re: Techniques for reducing memory needed on: November 29, 2010, 05:32:48 pm
Thanks for the replies. From my reading of the docs. PROGMEM can not be written to when the program is running - it is read only. Did I get that wrong?

I can see the value of off loading static stuff like lookup tables or static string data but I tend not to have much of that.

Also, I do not see how Serial.print of dynamic vars (e.g. when debugging) is helped by PROGMEM. Again, perhaps I misunderstood the docs.
49  Forum 2005-2010 (read only) / Syntax & Programs / Techniques for reducing memory needed on: November 29, 2010, 03:29:43 pm
Hi - I'm at a 'post-beginner', 'pre-intermediate' Wiring/C++ programming level. I've created custom libs, etc. and generally can get stuff done (tho' often with help.. ).

Anyway - with a recent project with some custom classes for controlling LEDs on an atmega168 I ran into what had to be memory issues: if I added Serial.print statements, the program would stop working. The sketch itself only took up @ 1/3 of available storage space.

To save ram I made sure that I:
--used bytes/chars instead of ints where possible
--used bitshifting instead of arrays where possible

I looked into PROGMEM but there wasn't much that was static so ended up not using it.

Are there other relatively easy things to do? If not, what would be a next step? Is it possible to store functions in PROGMEM? (and/or is that worth the effort).

Library (class) instances seem to take up lots of memory but the alternative is more confusing/tedious/harder programming (e.g. having to have loads of global variables).

tx for any tips!



50  Forum 2005-2010 (read only) / Syntax & Programs / Re: Interface reprap firmw with adafruit stepper libr on: November 14, 2010, 11:19:05 pm
I'm not using steppers in this project - it's a very old 36" HP plotter that I am reviving- this thing is massive! It has 24v motors w/ quad encoders and I'm controlling them through 2 Gamoto boards (http://www.gamatronix.com/product_info.php/manufacturers_id/10/products_id/28). I am using the step/direction capability of the Gamoto firmware so interfacing with RepRap was trivial.

Processing is pretty easy to get up with - loads of example code for serial <-> to Arduino. You can just concatenate a line feed after each string you send. If you haven't done much serial stuff with Arduino, maybe take a pitstop from the RepRap stuff and do some test sketches.

Here's my Processing serial code - there are a few dependencies that will need to get stripped out. You would need to call 'checkSerialInput()' from the Processing draw() function.

Code:
import processing.serial.*;
 
Serial sPort;      
boolean serialActive = false;
String dataIn;


void openSerialConnection() {
  sPort = new Serial(this, Serial.list()[0], 115200);
  serialActive = true;
}

void closeSerialConnection() {
  if (serialActive == true) {
    sPort.stop();  // close serial
  }
}

void sendCommand(String s) {
 if (serialActive == false) return;
  int ln = s.length();
  for (int i = 0; i < ln; i++) {
    sPort.write(s.charAt(i));
  }
}

String checkSerialInput() {

  String tmpString = "-1";
  if (serialActive == false) return tmpString;

  while (sPort.available() > 0) {
    char c = sPort.readChar();

    if (c == '*') {
      logEvent(dataIn);
      tmpString = dataIn;
      dataIn = "";
      return tmpString;
    }
    else  if (c == '$') {
 
      if (plottoState == PRINTING) {
        tmpString = "P";
        return tmpString;
      }
    }
    else  if (c == '@') {
      tmpString = "R";
    }

    else {
      dataIn += c;
    }
  }
  return tmpString;
}
51  Forum 2005-2010 (read only) / Syntax & Programs / Re: Interface reprap firmw with adafruit stepper libr on: November 14, 2010, 04:49:01 pm
I guess it depends on how you plan to ouput your gcode. There seem like lots of variations. RepRap (apparently) uses this:
http://objects.reprap.org/wiki/RepRapGCodes

but I am using the 3rd gen firmware right now and it doesn't conform to that standard. I plan to switch over eventually. I'm no expert on this stuff but what I plan to do is use that standard above and then preprocess the source gcode in the client to insure that it comforms rather than tinkering with the firmware. That said, I still prefer an explicit char to designate the end of a cmd rather than line endings. Maybe I'll get over that...
52  Forum 2005-2010 (read only) / Syntax & Programs / Re: Interface reprap firmw with adafruit stepper libr on: November 13, 2010, 09:29:36 pm
Which part didn't work - using serial monitor to send commands? It should work fine. I forget what the RepRap firmware uses to indicate the end of a cmd. I am using '*' - so in sending the gcode below (describes a circle within a square) I would send G01X399.266Y399.273*

If you put some print statements in the Arduino code you can see what is getting received and the state of things.


Code:
G00      Z0
G00      X0.734375      Y399.273
G01      Z-1
G01      X399.266      Y399.273
G01      X399.266      Y0.746094
G01      X0.734375      Y0.746094
G01      X0.734375      Y399.273
G00      Z0
G00      X345.828      Y234.496
G01      Z-1
G01      X345.287      Y222.486
G01      X343.693      Y210.76
G01      X341.091      Y199.36
G01      X337.524      Y188.326
G01      X333.037      Y177.702
G01      X327.675      Y167.528
G01      X321.481      Y157.847
G01      X314.5      Y148.701
G01      X306.776      Y140.13
G01      X298.353      Y132.177
G01      X289.275      Y124.884
G01      X279.588      Y118.293
G01      X269.334      Y112.445
G01      X258.559      Y107.382
G01      X247.306      Y103.145
G01      X235.62      Y99.7777
G01      X223.546      Y97.3206
G01      X211.126      Y95.8156
G01      X198.406      Y95.3047
G01      X185.687      Y95.8156
G01      X173.268      Y97.3206
G01      X161.193      Y99.7777
G01      X149.508      Y103.145
G01      X138.255      Y107.382
G01      X127.48      Y112.445
G01      X117.227      Y118.293
G01      X107.54      Y124.884
G01      X98.4628      Y132.177
G01      X90.0401      Y140.13
G01      X82.3161      Y148.701
G01      X75.3351      Y157.847
G01      X69.1413      Y167.528
G01      X63.779      Y177.702
G01      X59.2923      Y188.326
G01      X55.7257      Y199.36
G01      X53.1233      Y210.76
G01      X51.5294      Y222.486
G01      X50.9883      Y234.496
G01      X51.5294      Y246.506
G01      X53.1233      Y258.233
G01      X55.7257      Y269.634
G01      X59.2923      Y280.667
G01      X63.779      Y291.292
G01      X69.1413      Y301.466
G01      X75.3351      Y311.147
G01      X82.3161      Y320.293
G01      X90.0401      Y328.864
G01      X98.4628      Y336.817
G01      X107.54      Y344.109
G01      X117.227      Y350.701
G01      X127.48      Y356.549
G01      X138.255      Y361.612
G01      X149.508      Y365.848
G01      X161.193      Y369.215
G01      X173.268      Y371.672
G01      X185.687      Y373.177
G01      X198.406      Y373.688
G01      X211.126      Y373.177
G01      X223.546      Y371.672
G01      X235.62      Y369.215
G01      X247.306      Y365.848
G01      X258.559      Y361.612
G01      X269.334      Y356.549
G01      X279.588      Y350.701
G01      X289.275      Y344.109
G01      X298.353      Y336.817
G01      X306.776      Y328.864
G01      X314.5      Y320.293
G01      X321.481      Y311.147
G01      X327.675      Y301.466
G01      X333.037      Y291.292
G01      X337.524      Y280.667
G01      X341.091      Y269.634
G01      X343.693      Y258.233
G01      X345.287      Y246.506
G01      X345.828      Y234.496
G01      X345.828      Y234.496
G00      Z0
M5
M9
M2
53  Forum 2005-2010 (read only) / Syntax & Programs / Re: Interface reprap firmw with adafruit stepper libr on: November 13, 2010, 10:37:57 am
Hi - I've also adapted the RepRap code for an X/Y plotter type machine. I wrote the client app in Processing - it's pretty easy. There are various RepRap clients out there (Replicator, etc.) but I couldn't get them to work and my project needs a customizable client anyway.

If you just want to test your firmware, you can use the serial monitor (or any terminal app) to send single lines of gcode.
54  Forum 2005-2010 (read only) / Syntax & Programs / Re: Is this possible (newb question) on: November 13, 2010, 10:46:40 am
Work out the logic with pencil and paper  (flow chart, etc.) before you try to code it. That way you don't get tangled up in code syntax while trying to figure out what it is you are trying to say (in code).

Oh - when you get to the hardware part, look up "debouncing" for the switches - a potential gotcha.
55  Forum 2005-2010 (read only) / Syntax & Programs / Re: PID Library motor control example? on: November 10, 2009, 08:02:11 am
Hi -

I first wrote my own PID controller and got close but tuning was very tricky. I also tried the PID library but didn't have any success with it (probably operator error - my patience was wearing thin).

I finally went with the Gamoto motor controllers - $100 and very feature complete. Learned (only partially, alas) a valuable lesson @ build vs buy. The pleasure and challenge of building sometimes (often...) results in much wasted time and a stalled project. Trying to pick my build challenges more carefully now....

Anyway I can't help with the PID lib but here are 3 sources for cheap PID motor controllers:

http://www.gamatronix.com/product_info.php/products_id/28
http://www.geckodrive.com/products.aspx?n=711937
http://www.uhu-servo.de/servo_en/index.htm

Also, if your encoder is high resolution, the Arduino will not be able to handle the frequency of interrupt events.

Cheers,
---Roy
56  Forum 2005-2010 (read only) / Syntax & Programs / Re: PID Library motor control example? on: August 21, 2009, 10:15:24 pm
 
Quote
position control is very difficult using a DC motor, low or no holding torque at setpoint.

Actually that is not true. I have used the Gamoto boards and they have full torque at holding setpoint with DC motors.  PID w/ a velocity profile = accurate position + speed control.

Anyone done this? I have seen example videos on the web but no example code.

--Roy
57  Forum 2005-2010 (read only) / Syntax & Programs / PID Library motor control example? on: August 21, 2009, 09:20:52 pm
Hi - I'm having some trouble setting up the PID library to use for motor control. Does anyone have a sketch/code they would be willing to share?

I am running a DC motor with encoder, etc. and want to see if I can do accurate positioning with the PID library.

Thanks!

--Roy
58  Forum 2005-2010 (read only) / Syntax & Programs / Re: too frequent Serial.print() calls == locking up? on: October 29, 2010, 10:41:06 am
Thanks all. Seems like my problem is on the receiving end - too much data coming in too quickly.
59  Forum 2005-2010 (read only) / Syntax & Programs / too frequent Serial.print() calls == locking up? on: October 28, 2010, 02:09:16 pm
Debugging my project I put in Serial.print(etc) to determine the state of things. I find sometimes that if I don't also put in delay(n), the Arduino will freeze up and stop responding.

At least I am attributing this "locking up" to too many/frequent Serial calls. Does this seem a likely culprit? My expectation was that it would just overwrite any thing that was already in the buffer.

Is there a way to increase the serial buffer size or is this a chip limit.

thanks!
60  Forum 2005-2010 (read only) / Syntax & Programs / Re: "undefined reference to" ...a function i on: October 21, 2010, 09:17:17 am
Not using the block declaration method results in errors:

Code:
extern "C" byte getPenStatus(){
  return pen_status;
}

Error msg: previous declaration of 'byte getPenStatus()' with 'C++' linkage

Quote
CONVERSION_06_MEGA.cpp: In function 'byte getPenStatus()':
CONVERSION_06_MEGA:21: error: previous declaration of 'byte getPenStatus()' with 'C++' linkage
CONVERSION_06_MEGA:74: error: conflicts with new declaration with 'C' linkage


The block method seems to work though so  smiley
Pages: 1 2 3 [4] 5 6 ... 20