Collecting data with Arduino and Python

More
14 Aug 2012 11:34 #23158 by VNR
andypugh:

The Mesa 7i87 might have worked for you, plugged into the 7i77 smart-serial port.
........
I set up a UART on my Mesa card and have the Arduino talking 1Mb serial to a realtime HAL component. That was quite involved (custom Mesa firmware and changes to the Hostmot2 driver), but might also be an option.

Is the protocol between the Mesa card and the Arduino handled by firmware in the Mesa card ? If it so, could be implemented a modbus/etercath/devicenet or other protocol in the firmware ? (may be using a 7i44 not a 7i77)
Thanks you in advance,
VNR

Please Log in or Create an account to join the conversation.

More
14 Aug 2012 11:54 #23160 by andypugh
Replied by andypugh on topic Re:Collecting data with Arduino and Python
VNR wrote:

Is the protocol between the Mesa card and the Arduino handled by firmware in the Mesa card ? If it so, could be implemented a modbus/etercath/devicenet or other protocol in the firmware

The Mesa firmware only sends/receives 8-bit data packets. All the protocol is handled at the Arduino and HAL ends.
I wrote a HAL comp for the job.
So, what you propose would be possible, but might be more easily done with the userspace serial driver.

Please Log in or Create an account to join the conversation.

More
14 Aug 2012 15:29 #23169 by PCW
Its also possible to make the Arduino speak LBP at 1 Mbps so it can be a standard sserial remote with "discovery" and all that, so it would need no special support on the LinuxCNC end. 1 Mbps is pretty decent for real time and should be fine with 1-2 KHz servo thread rates. We're looking at adding some autobaud code to SSLBP (for our newer 4 and 10 Mbps capable cards) so 1M baud could be added to the search list

Please Log in or Create an account to join the conversation.

More
14 Aug 2012 16:56 #23172 by mcenter
Replied by mcenter on topic Re:Collecting data with Arduino and Python
I only need to read the spindle power in around 1 second intervals. I really don't care when I record a reading, as long as I know when a reading has been taken within .1 second, or so.

Sometimes, I will use a screwdriver for a pry-bar. I always keep a Crescent wrench handy, although I have SAE and metric wrenches from very small to quite large with extra copies. The trick is realizing when you really should use a pry-bar, a box end wrench, or a gas hatchet and sledge hammer.

This is the HAL I used:
loadusr -Wn datarecord data_recorder.py

net record-flag datarecord.record <= motion.digital-out-00
net spindle-speed datarecord.sp <= motion.spindle-speed-out
net x-rel-position datarecord.xpos <= halui.axis.0.pos-relative
net y-rel-position datarecord.ypos <= halui.axis.1.pos-relative

A waitusr command would be superfluous.

Using M62 P00 followed by G1 X1 Y1 MDI commands (M62 doesn't take action until motion command), the signals change in the watch window, but datarecord pin values do not. (As seen in the attached watch window.

My Python script only writes the .csv header for the file, apparently h is never set to TRUE.

Thanks for all the input. I am still very much in the learning phase regarding linuxCNC, HAL, Python and C. I do plan to implement this as a comp later for a learning exercise. But, my summer is almost over, and I am behind schedule on my research. If I can't resolve these issues, I'll be out there with a clipboard and a stopwatch (think gas hatchet and sledge hammer).

File Attachment:

File Name: data_recorder.py
File Size:2 KB
Attachments:

Please Log in or Create an account to join the conversation.

More
14 Aug 2012 17:37 #23184 by andypugh
Replied by andypugh on topic Re:Collecting data with Arduino and Python
I think the problem is that your Python code runs to completion the first time, then is not called again,

Your Python code needs to set itself up, issue a hal_ready then enter a busy-loop which polls the data. Unlike realtime components userspace components are not polled by the threads.

(Or, all this could be wrong, I am not very good at reading Python)

Please Log in or Create an account to join the conversation.

More
14 Aug 2012 18:00 #23189 by mcenter
Replied by mcenter on topic Re:Collecting data with Arduino and Python
Andy,

I think you are pointing me in the right direction. However, the code does not complete until LinuxCNC shuts down. In other words, the file opens when LinuxCNC begins, however it is not called again until shut down.

Mark

Please Log in or Create an account to join the conversation.

More
14 Aug 2012 19:02 #23205 by ArcEye
Replied by ArcEye on topic Re:Collecting data with Arduino and Python
I don't know if posting it removed indentation and I have never seen the referencing you used for the pins before

What happens if you write it like this?
try:
    basetime = time.time()
    while 1:
        delT = time.time() - basetime
        if h.record == 1:
        ain = pollArduino()
        f.write(str( h.xpos) +","+ str(h.ypos)+','+str(ain)+','+str(h.sp)+','+str(delT)+'n')
        time.sleep(1)

except (KeyboardInterrupt,):
    raise SystemExit, 0

regards

Please Log in or Create an account to join the conversation.

More
14 Aug 2012 21:20 #23212 by mcenter
Replied by mcenter on topic Re:Collecting data with Arduino and Python
ArcEye,

Yes, I think l the indents were stripped. And that is terribly important in Python.
The references are similar to how Jeff Epler did it in his arduino.py script.
My Python script works when executed outside LinuxCNC in conjunction with halrun.
But, I will try it the way you suggest. I think it is less confusing.

I will try to post my script again.

Mark

File Attachment:

File Name: data_recor...7c37c.py
File Size:2 KB
Attachments:

Please Log in or Create an account to join the conversation.

More
15 Aug 2012 01:28 #23219 by mcenter
Replied by mcenter on topic Re:Collecting data with Arduino and Python

File Attachment:

File Name: data_recor...52ea7.py
File Size:2 KB


I am having problems posting my file. Maybe it will work this time.

Mark
Attachments:

Please Log in or Create an account to join the conversation.

More
15 Aug 2012 01:31 #23220 by mcenter
Replied by mcenter on topic Re:Collecting data with Arduino and Python
Sorry, I should have read this before posting

File Attachment:

File Name: data_recorder.txt
File Size:2 KB


www.linuxcnc.org/index.php/english/compo...&id=342&catid=29#342
Attachments:

Please Log in or Create an account to join the conversation.

Time to create page: 0.092 seconds
Powered by Kunena Forum