Wednesday, January 18, 2017

Minimalist XY firmware for arduino leonardo + CNC Shield

everything is hardcoded
the commands contain relative movements
there's no units or you could say the units are motor steps

only XY are taken in considerations

to move the pen by ( 12,23 ) steps the command is

G0 X12 Y23 Z0

//the basic hardware control was inspired HC_CNC_Shield_Test by Andrew Davies

#define EN 8

#define X_STEP 2
#define X_DIR 5 
#define Y_STEP 3
#define Y_DIR 6
#define Z_STEP 4
#define Z_DIR 7

#define A_DIR 13  /* Direction pin for Aux driver. Requires D13 and A-DIR pins to be shorted */
#define A_STEP 12 /* Direction pin for Aux driver. Requires D12 and A-STEP pins to be shorted */

#define X_ENDSTOP 9   /* X axis endstop input pin */
#define Y_ENDSTOP 10  /* Y axis endstop input pin */
#define Z_ENDSTOP 11  /* Z axis endstop input pin */
#define ABORT A0  /* Abort input pin */
#define HOLD A1   /* Hold input pin */
#define RESUME A2 /* Resume input pin */

#define COMMAND_SIZE 128
char command[COMMAND_SIZE];
byte serial_count = 0;
boolean bytes_received = false;

void setup()
{
    /* Configure the steper drive pins as outputs */ 
  pinMode(EN, OUTPUT); 
  pinMode(X_DIR, OUTPUT); 
  pinMode(X_STEP, OUTPUT); 
  pinMode(Y_DIR, OUTPUT); 
  pinMode(Y_STEP, OUTPUT); 
  pinMode(Z_DIR, OUTPUT); 
  pinMode(Z_STEP, OUTPUT); 
  pinMode(A_DIR, OUTPUT); 
  pinMode(A_STEP, OUTPUT); 
  
  /* Configure the control pins as inputs with pullups */
  pinMode(X_ENDSTOP, INPUT_PULLUP);
  pinMode(Y_ENDSTOP, INPUT_PULLUP);
  pinMode(Z_ENDSTOP, INPUT_PULLUP);

  pinMode(ABORT, INPUT_PULLUP);
  pinMode(HOLD, INPUT_PULLUP);
  pinMode(RESUME, INPUT_PULLUP);

  /* Enable the X, Y, Z & Aux stepper outputs */
  digitalWrite(EN, HIGH); //Low to enable
  Serial.begin(9600);
}

void loop()
{
  char c;
  if( Serial.available() > 0 )
  {
    c = Serial.read();
    if( c != '\n' )
    {
        command[serial_count] = c;
        serial_count++;
    }
    else
    {
        command[serial_count] = 0;
        serial_count++;
    }
    bytes_received = true;
  }
  if( bytes_received && ( c == '\n' ) )
  {
    doit( command );
    serial_count = 0;
    bytes_received = false;
  }
}

void doit( char *input )
{
  char* command = strtok( input, " \n" );
  int G_val = -1;
  long X_val = 0;
  long Y_val = 0;
  long Z_val = 0;
  while( command != 0 )
  {
    switch( command[0] )
    {
      case 'G':
        G_val = atoi( command + 1 );
      break;
      case 'X':
        X_val = atol( command + 1 );
      break;
      case 'Y':
        Y_val = atol( command + 1 );
      break;
      case 'Z':
        Z_val = atol( command + 1 );
      break;
    }
    command = strtok(0, " \n" );
  }
  char mesg[32];
  sprintf( mesg, "%d %ld %ld %ld", G_val, X_val, Y_val, Z_val );
  Serial.println( mesg );
  digitalWrite(EN, LOW); //Low to enable
  motorizin( G_val, X_val, Y_val, Z_val );
  digitalWrite(EN, HIGH); //Low to enable
}

//------------------------------------------------------------------------------
void motorizin( int G_val, long X_val, long Y_val, long Z_val )
{
  switch( G_val )
  {
    case 0:
    case 1:
      line( X_val, Y_val, Z_val );
    break;
  }
}

//------------------------------------------------------------------------------
//first version of this program - only relative moves supported
//------------------------------------------------------------------------------
void line( long dx, long dy, long dz )
{
  digitalWrite( X_DIR, dx >= 0?LOW:HIGH );  
  digitalWrite( Y_DIR, dy >= 0?LOW:HIGH ); 
  long adx = abs( dx );
  long ady = abs( dy );
  if( adx >= ady ) 
  {
    subplot( 0, adx, ady );
  }
  else
  {
    subplot( 1, ady, adx );
  }
}

//------------------------------------------------------------------------------
void subplot( bool horizVert, long dx, long dy )
{  
  long D = 2 * dy - dx;
  bool stepy = false;
  for( long x = 1; x <= dx; x++ )
  {
    if( D > 0 )
    {
       stepy = true;
       D = D - dx;
    }
    D = D + dy;
    if( horizVert == 0 )
    {
      subsubplot( true, stepy );
  }
  else
  {
      subsubplot( stepy, true );
  }    
  stepy = false;
  }
}

//------------------------------------------------------------------------------
void subsubplot( long stepx, long stepy )
{
  if( stepx > 0 )
  {
    digitalWrite( X_STEP, HIGH ); 
  }
  if( stepy > 0 )
  {
    digitalWrite( Y_STEP, HIGH ); 
  }
  delay( 10 );
  digitalWrite( X_STEP, LOW );  
  digitalWrite( Y_STEP, LOW ); 
}

Tuesday, January 17, 2017

Bresenham Line ( relative ) implementation
written/tested in Daz Studio but will be in an arduino Leonardo plotter firmware


var dirx;
var diry;

plot( -10, -3 );

function plot( dx, dy ) // this is a relative movement
{
  dirx = ( dx >= 0 );
  diry = ( dy >= 0 );
  var adx = Math.abs( dx );
  var ady = Math.abs( dy );
  if( adx >= ady ) 
  {
   subplot( 0, adx, ady );
  }
  else
  {
   subplot( 1, ady, adx );
  }
}

function subplot( horizVert, dx, dy )
{  
  var D = 2 * dy - dx;
  var stepy = 0;
  for( x = 1; x <= dx; x++ )
  {
    if( D > 0 )
    {
       stepy = 1;
       D = D - dx;
 }
    D = D + dy;
   if( horizVert == 0 )
   {
     subsubplot( 1, stepy );
 }
 else
 {
     subsubplot( stepy, 1 );
 }    
 stepy = 0;
  }
}

function subsubplot( stepx, stepy )
{
 debug( stepx, stepy );
}

Bresenham Line implementation in Daz Studio Script

// DAZ Studio version 4.9.2.70 filetype DAZ Script

//plot( 3, 10 );
//plot( 10, 3 );
//plot( -3, 10 );
//plot( 10, -3 );
//plot( 3, -10 );
//plot( -10, 3 );
//plot( -3, -10 );
plot( -10, -3 );

var dirx;
var diry;

function plot( dx, dy )
{
  var adx = Math.abs( dx );
  var ady = Math.abs( dy );
  dirx = dx >= 0; //replace by set motor x direction
  diry = dy >= 0; //replace by set motor x direction
  if( adx >= ady ) 
  {
   subplot( 0, adx, ady );
  }
  else
  {
   subplot( 1, ady, adx );
  }
}

function subplot( horizVert, dx, dy )
{  
  var D = 2 * dy - dx;
  var y = 0;
  for( x = 0; x <= dx; x++ )
  {
   if( horizVert == 0 )
   {
     subsubplot( x, y );
   }
   else
   {
     subsubplot( y, x );
   }
   if( D > 0 )
   {
     y = y + 1
     D = D - dx
   }
  D = D + dy
  }
}

function subsubplot( x, y )
{
 debug( !dirx ? -x : x, !diry ? -y : y ); 
}



New ideas for an A.I.

Stupid idea that gave rise to this

while trying to adapt the Bresenham line algorithm for the firmware of a CNC machine ( 2 stepper motors ) i was thinking "it would be a good thing to really understand the principle Bresenham founded this on. I think it's called "accumulation of error"

https://en.wikipedia.org/wiki/Bresenham's_line_algorithm

i would add that the "auto-correction" phase is the other important cog of that machine

-----

then i thought, simple machinations of this type could be the base for my A.I.

-----

then i thought in a way solving a problem is just re-stating the question, or rather the object at the center of this question. Among the infinity(?) of ways to restate it, we want to pick the re-stating that satisfies the questioner ... or ... pick the restating that


for example, the question "what is the universe?"

we determine the object of the question is "the universe"

we presume there are many ways to restate "the universe"

- something big
- something we live in
- something humans think it is
- something infinite
- something eternal
- something finite

then it gets complicated

----

since i want to stay on simplicity-road  ...

----

 i'll just keep in mind the idea of  re-stating ( paraphrasing, tautologies, vérité de la Palice  etc )


Sunday, January 1, 2017

I may try to invent an A.I. in 2017

so i'll post about this sometimes

--------
mcjAI - 00000

Maybe an important step in inventing an A.I. is to name it properly, for instance, the A.I. that strive to pass the Turing test could be named Fake-Human-Dialog'ers. Personally, the A.I. that interests me more is an Artist Intelligence, a machine that produces interesting art, like drawings, songs and storytellings. Not necessarily a machine that answers questions or invents other machines. But but but, maybe if i can devise an art-generating machine then, as an aside, it will be able to (understand and ) answer questions and invent machines.
----------

here's a test on a daz script that uses a dictionary to identify nouns and adjectives in a given text, then replaces them by other nouns and verbs



the original text was a translation of Nostradamus quatrains

------------
from vertiginous deepest matriarch of visceral europe man
a class-conscious houri will be heroic to helical people mesosphere
who will by his airstrip seduce a calculating multitude, likeness
his fat-head will increase in numerate generality of recent east"
------------------------------------
beasts subliminal with whig will nymph oxonian rivers,
heart-rending greater harpoon of woolly posterity will be against hister.
into a fighter of orang-utan will corny stagnant silky be drawn,
when wall-to-wall fen of germany observes nothing.
------------------------------------
in preshrunk gland very not far from venus,
unreadable questionable greatest ones of asia and of africa:
they are said to have come from soppy rhine and from molecule
hister cries, tears at malta and puffy ligurian sea-coast.
------------------------------------
amperage will not be regained,
it will be occupied by a black, proud, stocky and get-at-able man:
when lewd intervention of prone lumber-room is opened,
serried leakage of venice will be inviolate by hister.
------------------------------------
hardy scrappy and linnaean armed over-sensitive will sol-fa historic decorative furnace,
operatic unwitting chosen one, collective captives not returning
prenatal world's treacherous crime, delectable aperient politic irale - israel - not at ease,
barb, hister, malta, and unborn remittent unreflecting does not return.
Happy New Year !


Thursday, November 19, 2015

Maybe i could make a sort of counter, the number of consecutive days when i dont skip blogging, let do that, it's called the

CDWSB : 1 ( consecutive days without skipping blogging )

---------

I "monetized" my YouTube videos, which means i'll get a percentage of revenues for ads plastered on my YouTube videos.

I removed 20 or 30 of my videos that had contested music tracks, Youtube allowed them but monetized them and gave the profits to the claimants ... i didn't really know about that part of the deal.

Jamendo went full commercial and if they still have Creative Commons Licensed music, well they hide them pretty deep. I used to get music for my videos there

For now i'll use http://freemusicarchive.org/ and (re) check cc-mixter

Here's the first video i re-uploaded, after changing the music track
which was relatively easy in this case



It's also a demonstration of a free script for Daz Studio which lets you render looping animations from the point of view of a non looping camera - Basically it lets you make a 4 minutes video from 1 1 second long looping dance move

----

oh and i started a daily renders sequence on my deviantArt channel

so i'll make a habit of posting them here too and get many CDWSBs !



The Messenger

when i did that i was thinking about the song The Messenger by Daniel Lanois ( he was/is? producer for U2 )

The pyramid and the rings are meant to be a sort of tranmiter or receiver .... well it could be a transceiver you never know :) And her dance is a message received or transmitted  .... well it could be a transceived you never know :)

the 3840x2080 version of this image is here
http://mcasual.deviantart.com/art/The-Messenger-Daily-re-Render-0008-20151117-573048224