Forum

Welcome Guest 

Show/Hide Header

Welcome Guest, posting in this forum requires registration.





Pages: [1]
Author Topic: stripping down the code to bare minimum?
plottingma-
d
Newbie
Posts: 2
Permalink
Post stripping down the code to bare minimum?
on: October 6, 2018, 20:50
Quote

hello

hows it going
i have an idea and would like some help
im curently using the polargraph adfruit version code and its working fine.
this code:https://github.com/euphy/polargraph_server_a1
but id like to learn how to do it myself and was looking to try stripping down the code to the bare basic code needed.

so far the code
uses
sd card fucnitons
eeprom functions
pen up/down functions
and much more including gcode conversion.

but really thats to much to understand.just yet so im trying to create a simple sketch that allows me to just write something like this in loop to draw a square.
void loop(){
drawline(40,0 ) //i.e right 40
delay()
drawline(40.-40 ) //up 40
delay()
drawline( -40.-40)//left 40
delay()
drawline(-40,0)//down 40
}

is there someone that could help point me in the direction of which functions do the processing of kinematics.

i understand the theory of making a vplotter but still a bit over my head.
so far i have understood that i get lenght of thread moved per each step.

and if i know the distance from motor to motor i can then somehow create a x,y coordinates system and convert it to lenghts of thread to each motor and increment them as needed to create a line. but thats where i blow up hah.

if anyone could give me some advice it would be great

thanks

sandy
Administrator
Posts: 1333
Permalink
sandy
Post Re: stripping down the code to bare minimum?
on: October 7, 2018, 02:00
Quote

Hi plottingmad! Yes, the vast majority of the code in most drawbots is to handle the command protocol rather than the actual drawing mechanics. That's the good news, because it really means that the actual drawing mechanics are pretty small and simple.

This code that formed the AS220 machine (https://web.archive.org/web/20090522073800/http://www.as220.org:80/labs/Code/drawbotErikSatie.txt) was the first I saw with source attached. Some of this still lives on inside Polargraph actually - spiral pixel uses these curve routines.

It's reasonably understandable on it's own, and it's about as stripped back as you'll get I think, there's no comms or commands as such.

In Polargraph, look in the util.ino file for the kinematics - there's a couple of functions in there:

float getMachineA(float cX, float cY)
{
  float a = sqrt(sq(cX)+sq(cY));
  return a;
}
float getMachineB(float cX, float cY)
{
  float b = sqrt(sq((pageWidth)-cX)+sq(cY));
  return b;
}

https://github.com/euphy/polargraph_server_a1/blob/master/util.ino#L165-L174

Given a cartesian x and y, these two above work out the length of cord A and cord B, ie the distance to the top left and right corners of the surface.

long getCartesianX(float aPos, float bPos)
{
  long calcX = long((pow(pageWidth, 2) - pow(bPos, 2) + pow(aPos, 2)) / (pageWidth*2));
  return calcX;  
}
long getCartesianY(long cX, float aPos) {
  long calcY = long(sqrt(pow(aPos,2)-pow(cX,2)));
  return calcY;
}

https://github.com/euphy/polargraph_server_a1/blob/master/util.ino#L225-L242

The two above do it in the opposite way, converting the native machine coordinates (distance from the top corners) into cartesian coordinates. Note that you need to work out the cartesian X first, and use it as a parameter to work out the Y.

sn

plottingma-
d
Newbie
Posts: 2
Permalink
Post Re: stripping down the code to bare minimum?
on: October 8, 2018, 23:58
Quote

hey sandy thanks for the reply already i have understood allot more about whats going on..

and the code you gave me from AS220 Labs is very easy to read compared to a full blown vplotter with eeprom and such.
but as im not a naturally math man or programmer i still have more questions now.

in your code for the polargraph i notice you use the accel stepper lib can i ask why you did not make you own step function to drive them high low?
is the accel stepper lib good ?
im only asking as i have recently been trying to learn about interrupts and port manipulation via the amazing tut from iforce2d here :https://www.youtube.com/watch?v=fHAO7SW-SZI
which has really helped me learn more about motors.

i have taken out all the circle and drawing of the image to completely simplify it to just lines up,down,left or right
i have added some comments with an abundance of questions.sorry!
i was unable to get the original stepper.h to work as i have no clue what pins do step/dir on the adafruit v1 motor shield
i read here https://learn.adafruit.com/adafruit-motor-shield/faq
that these pins are used but with a serial-to-parallel latch which i think does not use step and dir ?
so i changed to the original AFmotor shield lib.

i have uploaded the code at paste bin with come more questions here.
https://pastebin.com/bJkdHDzE

i understand your getmachineA();
the same as the old drawbot code here
int a1= sqrt(pow(x1,2)+pow(y1,2));
int b1= sqrt(pow((w-x1),2)+pow(y1,2));

but if i get the distance to top right/left motors i.e length of steps i dont understand in which way i call up or down?is it minus for left and down and + for right and up?

thanks again man im going to be playing tonight.

sandy
Administrator
Posts: 1333
Permalink
sandy
Post Re: stripping down the code to bare minimum?
on: October 13, 2018, 01:53
Quote

Have a look at my version here: https://pastebin.com/kmM5nU7z I've not tested it but it compiles at least.

I've added some extra comments and cleaned up the variable names a bit to make them more clear hopefully.

You should use the AFMotor library if you've got an Adafruit style Motorshield with L293D H-bridge drivers. Those are not stepper drivers so there is no step+direction pins that you can simply drive high or low to make a step happen. You have to set the specific combination of the four stepper motor wires in a specific sequence in order to make a move.

Accelstepper supports non-blocking motor stepping and obviously acceleration. I think it's brilliant.

Regarding your last point, I'm not sure I understand. IF motorA is top-left, and motorB is top-right: Moving motorA plus will make the pen move down the drawing surface in a curve, swinging around motorB which isn't moving. Moving motorA minus will pull the pen up the page in the same arc.

Moving motorB plus will move the pen down in a curve, as it swings around motorA which isn't moving. Moving motorB minus will pull the pen up the page in the same arc.

All of the target positions are absolute, and positive though. It's not possible to move the pen to a negative position (it would be off the top of the machine!).

sn

Pages: [1]
Mingle Forum by cartpauj
Version: 1.0.34 ; Page loaded in: 0.04 seconds.