Hello Guest it is March 29, 2024, 04:38:05 AM

Author Topic: Arduino output as a input for mach3  (Read 5555 times)

0 Members and 1 Guest are viewing this topic.

Arduino output as a input for mach3
« on: December 25, 2016, 09:43:12 AM »
I  am constructing a robot arm to choose a red golfball from a group of golfballs of different colors. The balls are in a balanced que, the lowest always ready for the arm"fork " to come and fetch and deliver the ball based on the valid color knowledge from adruino to the waist baset or the red basket.

When used mach3 together with Adruino I can get in Adruduino output the color value 0-256 and in case of 170-256 the arm should "understand", that the present ball belongs to the red basket and react accordingly. In less that 170 values, the arm should turn abit more, to the next waistbasket.  My question is, is there anyway howto feed the Adrino output value to gcode and how to maniulate, teach the gcode to react accodingly.

 As You can see on my text, I am an ret basic school teacher and understand the coding less than my pupils used to know the difference between the alpabeths... 
Re: Arduino output as a input for mach3
« Reply #1 on: December 26, 2016, 07:39:20 PM »
Hi,
I can see two possibilities:
1) have the numeric input read by Mach3 using either serial input or Modbus input
2) use a DAC to reduce the numeric value to a true/false value and use it as a single input to Mach3

The first option is certainly doable but would require some knowledge of Mach3 and coding to achieve.
The second option may therefore have the advantage of simplicity. Essentially convert the digital data to
an analogue voltage followed by a comparator with a threshold which corresponds to 170/256.
I presume your 8bit data value is output as a parallel value, that is to say 1 bit per pin, 8pins?
If so you could cheat a little and do the whole DAC and compare in one quad opamp.

Let me know if the idea appeals and I'll post a circuit diagram of what I mean.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Arduino output as a input for mach3
« Reply #2 on: December 27, 2016, 05:03:15 AM »
Hi,
just had another thought which would be simpler still, why not program the Arduino to send one
pin high when the colour vaule is greater than 170? After all your programming the Arduino anyway...

Setting up Mach to accept a true/false is straight forward.

Gcode programs have no conditional statements so you cant use the true/false input
to select one bunch of statements when the input is false or do another bunch of statements
when true. There is one trick you might try to exploit: the 'value' of a #variable is 0 when
false or 1 when true. Your rotation command might look something like:

G1 A[45+#nnn*45]

So your robot arm would rotate 45 degrees when #nnn is 0, ie input false or 90 degrees when
#nnn is 1, ie input true.

As you can see this just exploits a numerical value associated with a true/false input.
Where such a scheme fails is if you want to do a bunch of statements for each alternative,
in which case you would have to write a macro as CE (Machs Visual Basic scripting language)
certainly does have conditional statements.

Craig

'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Arduino output as a input for mach3
« Reply #3 on: December 30, 2016, 12:37:23 AM »
Craig.  The idea is brilliant, but as you see you are dealing with an amateur. Could you write the needed macro and tell where in Mach3 I need to feed this macro as well?
Re: Arduino output as a input for mach3
« Reply #4 on: December 31, 2016, 11:26:29 PM »
Hi tapio,
my CE scripting is very poor, I've changed to Mach4 recently and am starting to gain some fluency in LUA.

A broad sketch:
1) your gcode job would look something like this

       G0 X0 Y0 Z0 A0  --your initial setup moves
       ....                    --      "
       ....                    --      "
       M150                -- this is your macro which is going to do the majority of the work, M150 is just a random name, any unused
                               -- macro number could be chosen, recommend 100 or greater but less than 200 as there are some useful
                               -- macros that ship with Mach3 starting at M200, would be a shame to overwrite them.
      G0 X0 Y0 Z0 A0   -- your final 'parking' moves
      M30                   -- end of job

2)    M150                 -- your macro
       inputvalue=getOEMDRO(nnn)   -- where nnn is the DRO number of your single bit input, will need to re-read the documentation
                                                    -- to find nnn
      if inputvalue then
             code ("G1 X5 Y2 A0 F20")   -- an example of the first move instruction to pick up a red ball
             code (".......")                    -- second move
             code (".......")                    -- third move and so on...
       else
              code("G1 X.....")               -- first move instruction to pickup a non red ball
              code(".......")                    -- second move and so on..
       end

As you can see really the macro only reads your single bit input and the does one bunch of moves or another bunch
depending on the value of the bit. A statement like:
code("G1 X0.....F30") is simply a way of executing G code lines from within a macro.
One thing to be aware of is that a move say code("X5.5") will cause the x axis to move but while that is happening the
CE interpreter will already be reading subsequent lines of code and queue the moves up. Mostly that's OK but sometimes
you need to ensure a move completes before doing the next one. If that's the case follow the critical move with:
code("G1....")   -- your move
while IsMoving()
wend
code("G1....")    -- your next move

The while loop just trundles along until the first move completes before it will do the next instruction.

Take advantage of the documentation available from Artsoft re CE scripting and there are a lot of examples which you
can study as well.

If I can help with specific problems within my limited CE ability I will, and there are plenty of CNCers on the forum who
are masters of CE.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Arduino output as a input for mach3
« Reply #5 on: March 04, 2017, 02:02:09 PM »
Craig
As I told this is not my favorite topic.  By now  I have managed to work with tsc320 conneted on the top of my robot  to study color, if the ball there if it is pink, when it returns value =1, if any other color, value =0.
 In Mach3 input I can see the position 1 or 2 to change  if I  show to it pink or white ball, so it seems basicly to work.
The main question lies where dam can I find Mach3  VB Script to open it and write  the Macro150?.
I wonder if it s s possible that you might write me an example ?
Re: Arduino output as a input for mach3
« Reply #6 on: March 04, 2017, 02:28:23 PM »
Hi,
there used to be some good videos on the Artsoft website about writing scripts but are missing at the moment.

The script editor is found on the 'Operator' tab, 'VB Script Editor'. It behaves much like a text editor like notepad. Write your script
and save as M150. If you click the folder icon you will see a list of the existing macros, you may be surprised how many there are.
Open some of them to see how they are written. M600 is a real doozy.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'

Offline Tweakie.CNC

*
  • *
  •  9,196 9,196
  • Super Kitty
    • View Profile
Re: Arduino output as a input for mach3
« Reply #7 on: March 05, 2017, 01:38:25 AM »
If it's any help the tutorial scripting video's can be found here : http://www.machsupport.com/videos/

Tweakie.
PEACE