Go Down

Topic: Using Polargraph 1.2 with Spindle (Read 187 times) previous topic - next topic

RussellandSusan

G'day Super Wizard Class Hackers,

I've been fumbling around and finally have Polargraph 1.2 working using the CNC Shield, two Pouolouullooouulo drivers.

It took some time but I have mapped all the pins to what the CNC Shield requires. The servo lifts and lowers the pen as needed etc etc etc... All 100%.

My problem however is that I want the 'pen up' and 'pen down' servo functions to turn a digital terminal 'on' or 'off'. I'm assuming that any changes need to be done in the Arduino code and not the Processing Software.

My ultimate goal is to have the machine drive a spindle, laser or similar.

Im not even sure which code is the right code to embed in this post.

Any help is appreciated.

Robin2

#1
Aug 08, 2018, 10:23 am Last Edit: Aug 08, 2018, 10:24 am by Robin2
My problem however is that I want the 'pen up' and 'pen down' servo functions to turn a digital terminal 'on' or 'off'. I'm assuming that any changes need to be done in the Arduino code and not the Processing Software.
That's my guess also.

You need to post the Arduino program - hopefully it is not very large and very complex. And. hopefully, there are easy-to-identify functions that control the servo.

If the program is too long to include in a Reply then add the .ino file as an attachment.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

RussellandSusan

To make things clear:
I am building a large scale XY Polar plotter for a school demonstration. To achieve this I am using:

Hardware:
Arduino UNO
CNC Shield v3
2x Pololu A4988 drivers
2 x NEMA 17 steppers
LED for 'spindle' - to be a relay or similar to control load once operating

Software:
Arduino IDE v1.0.5
Polargraph 1.2
Processing 1.5.1

Configuration:
200 step/rev
16th stepping



As requested:

I have narrowed things down to one section of code: penlift.ino

This is the entire file (note: this is part of a sketchbook including 14 .ino files)

Code: [Select]
/**
*  Polargraph Server. - CORE
*  Written by Sandy Noble
*  Released under GNU License version 3.
*  http://www.polargraph.co.uk
*  https://github.com/euphy/polargraph_server_a1

Penlift.

This is one of the core files for the polargraph server program. 
This file contains the servo calls that raise or lower the pen from
the page.

The behaviour of the pen lift is this:

If a simple "pen up", or "pen lift" command is received ("C14,END"), then the machine will
not try to lift the pen if it thinks it is already up.  It checks the value of the
global boolean variable "isPenUp" to decide this.

If a qualified "pen up" is received, that is one that includes a pen position (eg "C14,150,END"),
then the global "up" position variable is updated, and the servo is moved to that position,
even if it already is "up".  Because naturally, if the up position has changed, even if it
is already up, there's a good chance it won't be up enough.

The same goes for the

*/
#ifdef PENLIFT
void penlift_movePen(int start, int end, int delay_ms)
{
  penHeight.attach(PEN_HEIGHT_SERVO_PIN);
  if(start < end)
  {
    for (int i=start; i<=end; i++)
    {
      penHeight.write(i);
      delay(delay_ms);
#ifdef DEBUG_PENLIFT
      Serial.println(i);
#endif
    }
  }
  else
  {
    for (int i=start; i>=end; i--)
    {
      penHeight.write(i);
      delay(delay_ms);
#ifdef DEBUG_PENLIFT
      Serial.println(i);
#endif
    }
  }
  penHeight.detach();
}

void penlift_penUp()
{
  if (inNoOfParams > 1)
  {
#ifdef DEBUG_PENLIFT
    Serial.print("Penup with params");
#endif
    int positionToMoveFrom = isPenUp ? upPosition : downPosition;
    upPosition = atoi(inParam1);
    penlift_movePen(positionToMoveFrom, upPosition, penLiftSpeed);
  }
  else
  {
    if (isPenUp == false)
    {
      penlift_movePen(downPosition, upPosition, penLiftSpeed);//
     
    }
  }
  isPenUp = true;
}

void penlift_penDown()
{
  // check to see if this is a multi-action command (if there's a
  // parameter then this sets the "down" motor position too).
  if (inNoOfParams > 1)
  {
    int positionToMoveFrom = isPenUp ? upPosition : downPosition;
    downPosition = atoi(inParam1);
    penlift_movePen(positionToMoveFrom, downPosition, penLiftSpeed);
  }
  else
  {
    if (isPenUp == true)
    {
      penlift_movePen(upPosition, downPosition, penLiftSpeed);
    }
  }
  isPenUp = false;
}
#endif




From what I can tell - If I were to change the following two sub routines from...

Code: [Select]
void penlift_penUp()
{
  if (inNoOfParams > 1)
  {
#ifdef DEBUG_PENLIFT
    Serial.print("Penup with params");
#endif
    int positionToMoveFrom = isPenUp ? upPosition : downPosition;
    upPosition = atoi(inParam1);
    penlift_movePen(positionToMoveFrom, upPosition, penLiftSpeed);
  }
  else
  {
    if (isPenUp == false)
    {
      penlift_movePen(downPosition, upPosition, penLiftSpeed);//
     
    }
  }
  isPenUp = true;
}

void penlift_penDown()
{
  // check to see if this is a multi-action command (if there's a
  // parameter then this sets the "down" motor position too).
  if (inNoOfParams > 1)
  {
    int positionToMoveFrom = isPenUp ? upPosition : downPosition;
    downPosition = atoi(inParam1);
    penlift_movePen(positionToMoveFrom, downPosition, penLiftSpeed);
  }
  else
  {
    if (isPenUp == true)
    {
      penlift_movePen(upPosition, downPosition, penLiftSpeed);
    }
  }
  isPenUp = false;
}


to something like....

Code: [Select]
void penlift_penUp()
{
  if (isPenUp == false)
  {
    digitalWrite(12, LOW);
  }
  isPenUp = true;
}

void penlift_penDown()
{
  if (isPenUp == true)
  {
    digitalWrite(12, HIGH);
  }
  isPenUp = false;
}


Where I get lost is how 'penlift_penUp' and 'penlift_penDown' are called. Also I get lost in the 'penlift_movePen' subroutine.

I have tried to make membership on the polargraph site's forum however there is a problem and I cant make an account  **sad face**

RussellandSusan

UPDATE:

Threw the code in and gave it a crack. Seems to work however the LED is quite dim making me thing that the output is PWM'd in some way.

Robin2

#4
Aug 09, 2018, 08:50 am Last Edit: Aug 09, 2018, 08:51 am by Robin2
Seems to work however the LED is quite dim making me thing that the output is PWM'd in some way.
At the top of your program have you set pin 12 as OUTPUT with pinMode(12, OUTPUT);

And are you sure that pin 12 is not used for anything else? - it is one of the SPI pins

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

RussellandSusan

Hi Robin2,

Yeah, I went page by page through the code and verified that pin 12 is not used for any other function. I have also checked pins 13 and 9.

Same thing - I can make the pins give a HIGH (255) value during the Void Setup routine however when the program enters into the next loop within loop within loop sections, I get lost. I also have no oscilloscope to 'see' what is actually happening.

I'm diving back into it today. This is as much about achieving the outcome as much as it is the journey there...


RussellandSusan

Hello all again,

I have sorted it out. I will post in time when the coding is tidy but it looks like I have a system that allows for either solenoid or servo type operation. This gives the Polargraph program more functionality.


Go Up