LinuxCNC S-Curve Accelerations

More
3 years 7 months ago #267666 by rodw
Replied by rodw on topic LinuxCNC S-Curve Accelerations
Great stuff.

Just a heads up in /src/emc/motion/motion.c and associated files, there are some debug pins that are designed for developers dealing with this sort of stuff to debug work using halshow. Basically, you just publish the data you are looking at to a hal pin. You might need them yet.
The following user(s) said Thank You: Grotius

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

More
3 years 7 months ago #267800 by Grotius
Replied by Grotius on topic LinuxCNC S-Curve Accelerations
Hi,

Yes Rod, it's handyer to create hal pins or params to debug.

Yesterday and today i finished the scurve component conversion from c++ to c.

I have a question related to the c code of the component.

In one function (a big function) i am a little confused about using free memory and clear a vector.

line 1421 if i free the memory and do a vector cleanup. The component will do nothing the second curve request.
The timer of the component will stay to run.

At the moment it's outcommented, the component will run repeatedly without any problems, but
i did not take care of free memory. Is this a problem?

A video the component running in axis, with halsope :
link to github video

The video looks oke to me. Its 2 channels, so the acc curve it only shown as value in the left.

For the rest of the day, i now will go on with the tc.c file, adding more debug params.
And will try to look at the velocity profile that is used.

 

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

More
3 years 7 months ago #267802 by rmu
Replied by rmu on topic LinuxCNC S-Curve Accelerations
free() just marks the memory as "free" but doesn't actually clean it. Don't use pointer after free()ing it, that is illegal, will lead to memory corruption and hard to track bugs.
The following user(s) said Thank You: Grotius

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

More
3 years 7 months ago #267851 by Grotius
Replied by Grotius on topic LinuxCNC S-Curve Accelerations
@rmu,

Thanks.
The component was running for 1.5 hours without any problem.

I started again working at the tp.c file.
At now finally is was able to control the tp. "Hacked +1".
But far from where i want to go with the code.

The way i made control is every cycle just add 0.002mm to the progress.
The progress (is actual line or arc lenght seen from start to current tp).
The progress value can also be a negative. So i have added little function for that to solve.
If we are close to the target, just go to the next gcode line.

This avoid's the so called "split cycle". Wich i previously called a "stitch".
The split cycle ensures exact endpoint reach in the next cycle.
The split cycle time can be a time like : 0.00035 sec to reach endpoint. Normally
the increment time is 0.001 sec, this can cause a displacement overshoot.

The control code:
Code:
    if(tc->progress<tc->target){          tc->progress+=0.002;     }     if(tc->progress>tc->target){          tc->progress-=0.002;     }     //! If close, finish.     T diff=netto_difference_of_2_values(tc->progress,tc->target);     if(diff<0.1){         tc->progress=tc->target;         tc->remove=1;     }

As a result lcnc gives a velocity output of : 0
This is perfect. It just moves the tp trough the program at a fixed increment value for each cycle.
The tc->remove is reset after call by excisting code.

Video how the program behaves:
video link

For every video i have directory in source code including the c source.

link to source code

In theory i could just put a scurve inside now. Who would preferr this?  Just a raw test now?

Vote please !!


 

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

More
3 years 7 months ago - 3 years 7 months ago #267854 by rodw
Replied by rodw on topic LinuxCNC S-Curve Accelerations
I think in real time linuxcnc, you are supposed to use hal_malloc instead of malloc. You might check that out.

If you allocate memory  with malloc, you the programmer must manage it. If you do not free it, a memory leak will ocurr and eventually, a memory overrun will ocurr and bad things happpen. here is why

When a program is compiled the code is written starting at the base of memory lets say at memory location 0x0000
Global (static) variables are created in what is called the heap starting at 0xFFFF in our super simple example and growing down.
Malloc allso allocates memory in the heap growing it down.

The stack starts at the top of the code and grows up. When a procedure is called, the memory for its variables are created in the stack. When the procedure is exited, the stack memory allocated to it is freed automatically.

So if you use malloc in a procedure and never free the memory before exiting, the next call to malloc of the same variable will mean that a new section of the heap is allocated (growing down). If the heap grows far enough, it can overwrite the stack (growing up) and that is when really bad unpredictable behaviour happens. This is because when you read a  malloced variable, it might have been overwritten by the stack. Likewise, you might call a procedure and executable code is overwritten by a call to malloc. it is your responsibility to manage memory allocation and deallocation!

In higher level languages, this memory management is maybe done for you.

Memory leaks may not be an issue in architecture where memory abounds, but  say you are programming a 64k 8088 device it is vital. Another example might be on an Arduino which might only have a 2k global memory space for variables and text.

Hope that helps.
Last edit: 3 years 7 months ago by rodw.

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

More
3 years 7 months ago #267858 by rmu
Replied by rmu on topic LinuxCNC S-Curve Accelerations

[...]
So the rule is for every call to malloc, you must also have a corresponding call to free BEFORE you exit the same procedure or you are setting yourself up for failure and you will spend days chasing random code errors due to memory overflow...

Hope that helps.
I'm sorry to say that, but that is not sound programming advice. Freeing dynamically allocated memory before exiting the procedure where you allocated it completely defeats the purpose of dynamic memory allocations.
The following user(s) said Thank You: rodw, Grotius

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

Time to create page: 0.365 seconds
Powered by Kunena Forum