faster Loop_event

If you have a question about the software please ask it here.

faster Loop_event

Postby odino87 » Tue May 09, 2023 7:06 pm

Hi to everyone here :)

I'm trying to develop a plugin to 3D scanning a relief.
It will implement a linear laser scanning procedure (parallel scanning to X axis and after each line it will move the Y axis).
I'm going to used a laser measure sensor that will measure the distance between the sensor itsel and the relief surface.
The sensor will be wired to an Arduino. The Arduino will read the analog input from the sensor and it will send the data to the PC.
The PC-Arduino communication is done using SerialPort .net component.
The plugin is quite complete ad the moment. I made a testing setup with an arduino that will spam random value to the PC and I'm using UCCNC in demo mode!
So in the end the sensor will send to the PC the distance data will the CNC head is moving, and the code will gather the Z value from the sensor, the X Y value from the UCCNC core and it will save this value in a file.

At this point what I want to improve before start making real scanning procedure is the collecting data transfer rate.
The main loop_event is called 2time per second, aka 25Hz. About 40ms between each loop.
The sensor is able to produce a correct measure in less tha 10ms, the response time is 5ms. About 8 times faster that the main loop_event.
Measuring the arduino capability I'm able to collect a value each 5-6ms.

Thanks for reading this Wall of text :D
any help is appreciate!

To surpass the speed of the loop_event I attached a dataRecived_Event to the serialPort object and now I'm able to collect the data from the arduino-sensor baiscally ad the same speed the arduino can generate is (as I said before about 5-6ms).
But now I have a "problem" with the x,y coordinate values that I collect form the plugininterface.
The code I use to get the x y coordinates is
Code: Select all
                   
double xpos = UC.GetXpos();
double ypos = UC.GetYpos();

and the generate file is something like this (first 3 value are the coordiante the last 3 value are the color of the point)
Code: Select all
2,81 0 8,1 68 68 68
2,81 0 7,8 66 66 66
2,81 0 7,8 66 66 66
2,81 0 8,1 68 68 68
3,15 0 8,1 68 68 68
3,15 0 7,8 66 66 66
3,15 0 7,8 66 66 66
3,15 0 8,4 71 71 71
3,15 0 8,1 68 68 68
3,15 0 7,8 66 66 66
3,15 0 8,1 68 68 68
3,495 0 8,4 71 71 71
3,495 0 8,1 68 68 68
3,495 0 7,8 66 66 66
3,835 0 8,1 68 68 68
3,835 0 8,4 71 71 71

as you can see there are a loot of duplicate value for the X axis. I think this is caused by the main loop_event that is called at 25Hz and the x,y values that are get from my code are updates at the rate of the main loop_event.
The final question is the follow: is it possibile to get THE REALTIME position of the CNC?
I mean the realtime values from the UCCNC core and not the 25hz updated values?
If I could do this my scanning time will be much lower.
odino87
 
Posts: 16
Joined: Mon Mar 20, 2023 3:02 pm

Re: faster Loop_event

Postby eabrust » Wed May 10, 2023 12:23 am

Hi Odino,

Sounds like a fun project. Are you currently collecting the x/y data points from the data_received event, or from the loop event directly?

I'm guessing even UCCNC core itself doesn't know real time location that fast, as it is polling the controller at some rate, probably faster than 25 hz, but not as fast as you're trying to get.

Just thinking of possible solution... if you're running the scanner back and forth along the X, are you able to interpolate the X location based off the commanded velocity and the time delta since last data was received event (once axis has accelerated and is running constant speed)?

Can I ask what you're using for a sensor?

regards
Eric
CraftyCNC: Plugins for UCCNC (and other neat stuff): http://www.craftycnc.com/plugins-for-uccnc/
eabrust
 
Posts: 357
Joined: Fri Sep 16, 2016 2:32 am
Location: Near Shirland IL, USA

Re: faster Loop_event

Postby odino87 » Wed May 10, 2023 8:44 am

Hi
actually I'm using a panasonic sensor, HG-C series (the price is in the range of 700€ for a new sensor).

Anyway I'm getting the X/Y data inside the data_recived event not directly from the loop_event. I did this because the slower Hz of the loop_event compared to the data_recived event.
I think that UCCNC should now (maybe) the correct real time position because it have to generate the correct timing pulse for the motor.
Maybe cncdrive can give us some advice about how to access that low level information (if it is avaiable).
For example using GRBL/Marlin I can send over and over the request for the real time position and the controller give me the (eximated by controller) real time position. The real time position is extimated by the low level controller based on speed/acceleration/movement timing, etc (I don't know the low level implemetation sorry).

I was evaluating interpolating the position between 2 point but before digging in some interpolation algorithm I want to be sure that there is no way I can access the low level information I'm looking for :D
odino87
 
Posts: 16
Joined: Mon Mar 20, 2023 3:02 pm

Re: faster Loop_event

Postby odino87 » Wed May 10, 2023 2:02 pm

I'll give you some other info about the speed and timing in my mind.
If I want to have a sample every 0.1mm and I can get 25 sample for second (the Hz from the loop_event) I'll get 2.5mm/sec of speed, so about 150mm/min.
If I move to 1000mm/min I'll get about 17mm/sec so 0.67mm between 2 point (they are too far away for a good scanning).
If I can acces to a really fast sampling, about 100 sample for second at 2000mm/min => 33.33mm/sec I'll get a 0.33mm between 2 sample point, and this kind of speed/resolution is kinda ok for me.

Data_recived event can give me data in this range of time... so now I need to know if there is a direct way (from the microcontroller) to get the exact position.
Or if I need to interpolate it
odino87
 
Posts: 16
Joined: Mon Mar 20, 2023 3:02 pm

Re: faster Loop_event

Postby Robertspark » Wed May 10, 2023 3:43 pm

look at linuxcnc as it will be able to provide actual realtime position data (if you run it with a parallel port) or at 1khz if you use an ethernet motion controller device.
Robertspark
 
Posts: 1892
Joined: Sat Sep 03, 2016 4:27 pm

Re: faster Loop_event

Postby odino87 » Wed May 10, 2023 4:07 pm

I'd like to remain on windows env and using UCCNC software to handle the machine :)
odino87
 
Posts: 16
Joined: Mon Mar 20, 2023 3:02 pm

Re: faster Loop_event

Postby cncdrive » Wed May 10, 2023 4:09 pm

You could create your own times or thread in a plugin which could be any fast, but you can never get realtime position data, because there is a communication delay between the mtion controller and the PC. This delay is about 20msec, so you cannot reach faster than about 50Hz update rate with a 20msec delay.
cncdrive
Site Admin
 
Posts: 4887
Joined: Tue Aug 12, 2014 11:17 pm

Re: faster Loop_event

Postby Robertspark » Wed May 10, 2023 5:54 pm

I guess at 20hz you could do an approximation of the position using a kalman filter, given you know the window is 20hz and you can estimate the position given the velocity and commanded position (distance to go)

at 20hz you have the standard deviation.....

good luck
Robertspark
 
Posts: 1892
Joined: Sat Sep 03, 2016 4:27 pm

Re: faster Loop_event

Postby odino87 » Wed May 10, 2023 7:50 pm

Yeah I think the only way to have a much dense mesh is using an interpolation algorithm.
In the mean time I can use the scanner procedure with a much slower speed (I can try 450mm/min and check che result) and then trying to improve the vertex value distrubution.
odino87
 
Posts: 16
Joined: Mon Mar 20, 2023 3:02 pm

Re: faster Loop_event

Postby Robertspark » Wed May 10, 2023 10:15 pm

I don't think it will work with uccnc, but there is always ROS that can be used with lidar scanners.

have a search of YouTube.
Robertspark
 
Posts: 1892
Joined: Sat Sep 03, 2016 4:27 pm

Next

Return to Ask a question from support here

Who is online

Users browsing this forum: Majestic-12 [Bot] and 16 guests