Forum

Welcome Guest 

Show/Hide Header

Welcome Guest, posting in this forum requires registration.





Pages: [1]
Author Topic: Mods for Mega version
airzone
Beginner
Posts: 33
Permalink
Post Mods for Mega version
on: February 2, 2013, 12:26
Quote

Hi,

I'm putting together a machine based on a mega board.Everything is on the cheap with bits that I have lying around here, and the occasional piece from company scrap.. In addition, the machine's home location isn't somewhere where I would safely leave a PC.
I have had to work out some way of interfacing with the machine without using anything extravagant, nor without relying on a laptop.

To the effect, I have added the capability for 2 buttons, and 2 LED's (or one bi-colour).. Pin allocation is per the below constants.

The buttons are: Set Home, and Execute from SD (reads comm.txt command list)
The LEDs are Ready and Busy.

You will need to update the set home command to be suited to your own machine, or perhaps I will be more motivated and calculate it!

If anyone wants it, feel free.

Michael_Mod.ino

const int pinSetHome = 22;
const int pinExecFromSD = 24;
const int pinStatusReady = 23;
const int pinStatusBusy = 25;

int currentPSHState;
int currentPEFSDState;

void Michael_Init()
{
  pinMode( pinSetHome, INPUT );
  pinMode( pinExecFromSD, INPUT );
  pinMode( pinStatusReady, OUTPUT );
  pinMode( pinStatusBusy, OUTPUT );
  
  currentPSHState = 0;
  currentPEFSDState = 0;
}

void Michael_SetStatusBusy( int CurrentState )
{
  if( CurrentState == 1 )
  {
    Serial.println( "MI - BUSY" );
    digitalWrite( pinStatusBusy, HIGH );
    digitalWrite( pinStatusReady, LOW );
  }
  else
  {
    Serial.println( "MI - READY" );
    digitalWrite( pinStatusBusy, LOW );
    digitalWrite( pinStatusReady, HIGH );
  }
}

String Michael_Execute( String input )
{
      
    // Execute command from SD = 
    // C34,comm.txt,END
    
    int ButtonState = 0;
    ButtonState = digitalRead( pinSetHome );
    if ( ButtonState == HIGH )
    {
      currentPSHState = 1;
    }
    else
    {
      if ( currentPSHState == 1 )
      {
        Serial.println( "MI - PinSetHome released" );
        currentPSHState = 0;
        return "C09,3920,3920,END";  // Replace with the SetHome command parameters from controller app
      }
    }
    
    ButtonState = 0;
    ButtonState = digitalRead( pinExecFromSD );
    if ( ButtonState == HIGH )
    {
      currentPEFSDState = 1;
    }
    else
    {
      if ( currentPEFSDState == 1 )
      {
        Serial.println( "MI - PinExecuteFromSD released" );
        currentPEFSDState = 0;
        return "C34,comm.txt,END"; // Requires comm.txt
      }
    }
        
    return input;
}

comms.ino comms_waitForNextCommand

    // and now read the command if one exists
    // this also sets usingCrc AND commandConfirmed
    // to true or false
    inS = comms_readCommand();

    
    inS = Michael_Execute( inS );  // Check button status
    
  }

impl_mega.ino

void impl_executeCommand(String &com)
{
  Michael_SetStatusBusy( 1 ); // Now busy

........ Original code!


  else
  {
    comms_unrecognisedCommand(com);
    comms_ready();
  }
  Michael_SetStatusBusy( 0 ); // Now Free
}

And of course the init code

void setup() 
{
  Michael_SetStatusBusy( 1 );   // Set bust light on - busy booting!
  Serial.begin(57600);           // set up Serial library at 57600 bps
  Serial.print(F("POLARGRAPH ON!"));
  Serial.println();
  configuration_motorSetup();
  eeprom_loadMachineSpecFromEeprom();
  configuration_setup();
  Michael_Init(); // Initialise button variables

  ..... original code here 

  delay(500);
  outputAvailableMemory();
  Michael_SetStatusBusy( 0 ); // Ready
}
sandy
Administrator
Posts: 1317
Permalink
sandy
Post Re: Mods for Mega version
on: February 2, 2013, 12:42
Quote

Hey Michael, cool stuff - I did something like this a while back (http://www.polargraph.co.uk/2012/03/polargraph-sd-plus-hoofer-doofer - the code is at http://code.google.com/p/polargraph/source/browse/embedded/branch/polargraph_server_mega_buttons/polargraph_server_mega_buttons.ino) except yours looks a bit more elegantly done. And I never wrote it up properly with a circuit diagram. Only thing I'd say is that you might be best off putting the "set home" command (C09,3920,3920,END) in as the first line of your comm.txt script rather than having the value hard-coded in the firmware. Of course, the side-effect of C09 is that the motors get locked anyway, so if you have a different C09 in your comm.txt then it'll override the initial value. Ok, talked myself out of that one.

Looks good! This is a perfect case for forking a la GIT - are you at all familiar with GIT vs SVN as a source code tracking system? I'm just starting to use GIT and am seeing the advantages of that for this sort of customisation.

sn

airzone
Beginner
Posts: 33
Permalink
Post Re: Mods for Mega version
on: February 2, 2013, 12:52
Quote

Hi Sandy,

I've not really played with git, other than to pull sources for various things. I set up a svn server at work about a month back, but my job scope has changed, and therefore won't be needing it anymore! This sounds like another opportunity to look into source management.

There is possibly a better way to handle the machine config though - maybe through the use of a config file on the SD card... Read the SD, find the machine init commands tailored to the specific machine, then run it.

i.e.

  return "C34,init.txt,END"

Michael

sandy
Administrator
Posts: 1317
Permalink
sandy
Post Re: Mods for Mega version
on: February 2, 2013, 19:50
Quote

I've used SVN for years but GIT for just a month or two and still haven't got my head around it. It seems superficially similar, but actually totally different as soon as I start using it properly.

Yep, a startup script would make sense if it could be relied upon to be there. There's plenty of space in EEPROM for stuff that needs to be non-volatile though - that's where the machine size and motor spec goes, and I think it's probably true that the pen width and the motor speed and acceleration should probably be in there too.

In principle, there's no reason why home point couldn't be secreted away in EEPROM too, but I've always been reluctant to have home point as a special thing that the machine itself needs to know about - I prefer having the machine as dumb, or as stateless as possible, and the controller be the thing that does that side of operations. I guess the genie is out the bottle with that one though, what with roving and vectors, so I don't know if that principle is worth much now.

There is a thing that a few folk have done with whereby the machine has a unique name, and as soon as it powers up, it connects to a server of some sort and downloads it's configuration from there. I quite like that idea because it separates concerns and moves some of the work to a place and format that might be easier to code.

sn

airzone
Beginner
Posts: 33
Permalink
Post Re: Mods for Mega version
on: February 8, 2013, 10:33
Quote

Hi Sandy,

I modified the source to include initialisation from an init.txt file.

Also, I modified the communications so that it can optionally output / input from 2 serial ports... The theory being that I want to use a bluetooth module for communications with the controller (when not using SD card) as my casing doesn't have a clean USB port, and BT is just so uber. However I still want to use USB serial in the event of some real diagnostics, and also to configure the BT module.
This mod is much more extensive (and unclean) as you can imagine.

If I could be bothered, I'd solder some expansion pins on the motor controller so that I could use the standard serial interface without any software mods. Anyway, when I suss out GIT, I'll set it up as a fork.

But in the mean time, I need to suss out some alignment / calibration issues I have

Alejandro-
de-
Montecrist-
o
Newbie
Posts: 15
Permalink
Post Re: Mods for Mega version
on: June 28, 2013, 01:20
Quote

hi airzone i trying upload your mod but appers problems with sd card, witch arduino uses you for upload your firmware to the mega^?
very very thanks

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