machinekit / machinekit-cnc

CNC stack split out into a separate package
Other
60 stars 37 forks source link

disentangling the trajectory planner API #21

Open ArcEye opened 6 years ago

ArcEye commented 6 years ago

Issue by mhaberler Wed Feb 4 08:27:24 2015 Originally opened as https://github.com/machinekit/machinekit/issues/476


The emc/tp code needs access to some config and status items. This is currently done by referencing the emcmot_config_t, emcmot_status_t and emcmot_joint_t structures directly. This is undesirable as it creates a data structure dependency, and makes decoupling harder.

The idea is to replace those references by callbacks which go through a struct passed down from using code; the tp would get/set values as needed through these callbacks. If a callback is NULL for a readonly value, a default value could be used instead.

These are the items referenced:

num_dio, num_aio - setup time, read-only - pass as parameters once

emcmot_config_t (all read-only): maxFeedScale double arcBlendGapCycles double arcBlendOptDepth int arcBlendEnable int arcBlendRampFreq double arcBlendFallbackEnable int

Plan: make those get_* callbacks to fetch values as needed Q1: do we need for changing these values on the fly? (like making them a pin/config item?) Q2: if callbacks not set, what would be sensible default values?

emcmot_status_t

read-only - plan: make those getter callbacks: net_feed_scale spindleRevs spindle.direction enables_new spindle_is_atspeed spindleSpeedIn Q: any sensible default values for the above?

read-write - make those getter/setter callback pairs; I guess these are must-have callbacks: spindleSync current_vel dtg spindle_index_enable spindleSync

write-only - make those setters, ignoring them if NULL callbacks requested_vel distance_to_go spindle.speed enables_queued

velocity and acceleration bounds from emcmot_joint_t: these look like config-time fixed (or does it make sense have those changeable on the fly?) tpGetMachineAccelBounds(PmCartesian * const acc_bound) tpGetMachineVelBounds(PmCartesian * const vel_bound)

the alternative to a table of getters/setters would be to provide pointers to the raw data (wherever that lives) decoupled from the actual structures; while simpler, we dont get change notification in the using code - the callback scheme would allow tacking an action onto any change

another method would be to move these items into the tp instance data, and provide getters/setters for the using code

what is preferrable: callbacks, data reference or make it instance data?

it's also conceivable to use a combination; e.g an using-code accessor for say current_vel, requested_vel etc; and callbacks for spindle* values which change rarely.

ArcEye commented 6 years ago

Comment by mhaberler Thu Feb 5 11:04:48 2015


ok, plans revised. On the spectrum "proper class encapsulation" to "best HAL integration" I'd go for the latter and handle all these variables as potential HAL pins (they easily can, but they do not have to be pins). It would mean tp becomes HAL-aware, which it currently is not. It would mean value access is by direct data reference, not getters/setters. There can still be "change callbacks" out of tp, but they might be optional (NULL allowed).

this means: all shared variables and parameters become hal_s32_t * and hal_float_t * pointers in a struct which will be allocated via hal_malloc() at tpInit() time. This should also be compatible with future configItems once we have them (it might mean configItem values need to live in the HAL shm segment).

ArcEye commented 6 years ago

Comment by mhaberler Sat Feb 21 14:36:24 2015


happy to report a milestone: disentangling complete and we're still above water.. meaning:

the tp and kinematics are now

the axis_mm.ini demo still runs no, noticable hiccups yet

vtp and kinematics are the RT module for trajectory planner and kins respectively in the 'show vtable' section you see the named vtable objects which are referenced by motion (refcnt 1)

mah@nwheezy:~/machinekit-polish/src$ halcmd -f -k halcmd: show comp Loaded HAL Components: ID Type Name PID State 748 User halcmd7233 7233 ready, u1:0 u2:0 732 User axisui 7207 ready, u1:0 u2:0 663 User inihal 7206 ready, u1:0 u2:0 628 RT comp RT ready, u1:0 u2:0 621 RT or2 RT ready, u1:0 u2:0 610 User hal_manualtoolchange 7192 ready, u1:0 u2:0 593 RT near RT ready, u1:0 u2:0 585 RT lowpass RT ready, u1:0 u2:0 575 RT limit2 RT ready, u1:0 u2:0 567 RT sim_spindle RT ready, u1:0 u2:0 536 RT hypot RT ready, u1:0 u2:0 505 RT ddt RT ready, u1:0 u2:0 272 RT motmod RT ready, u1:0 u2:0 270 RT vtp RT ready, u1:0 u2:0 268 RT trivkins RT ready, u1:0 u2:0 89 User halui 7173 ready, u1:0 u2:0 71 User iocontrol 7169 ready, u1:0 u2:0

halcmd: show vtable Exported vtables: ID Name Version Refcnt Context Owner 271 tp 2000 1 RT 270 vtp
269 trivkins 1000 1 RT 268 trivkins

halcmd:

cleaned branch: https://github.com/mhaberler/machinekit/tree/vtable-tp-and-kins-try2

ArcEye commented 6 years ago

Comment by mhaberler Sat Feb 21 21:33:57 2015


made a PR: https://github.com/machinekit/machinekit/pull/501 - looks stable but the shit job is still ahead: modifying 205 .hal files to add "loadrt tp" :-/

ArcEye commented 6 years ago

Comment by luminize Sat Feb 21 22:44:54 2015


I'll help, let's split the job

On 21 Feb 2015, at 22:33, Michael Haberler notifications@github.com wrote:

made a PR: #498 - looks stable but the shit job is still ahead: modifying 205 .hal files to add "loadrt tp" :-/

— Reply to this email directly or view it on GitHub.

ArcEye commented 6 years ago

Comment by mhaberler Sat Feb 21 22:58:26 2015


thanks! looks like a script job to me; must extract the name of the kinematics, example changes:

before:

# kinematics
loadrt trivkins
# motion controller, get name and thread periods from ini file
loadrt [EMCMOT]EMCMOT base_period_nsec=[EMCMOT]BASE_PERIOD servo_period_nsec=[EMCMOT]SERVO_PERIOD num_joints=[TRAJ]AXES

after:

# kinematics
loadrt trivkins
# trajectory planner
loadrt tp
# motion controller, get name and thread periods from ini file
loadrt [EMCMOT]EMCMOT base_period_nsec=[EMCMOT]BASE_PERIOD servo_period_nsec=[EMCMOT]SERVO_PERIOD num_joints=[TRAJ]AXES tp=tp kins=trivkins

or other kinematics:

# kinematics
loadrt pumakins
# motion controller, get name and thread periods from ini file
loadrt [EMCMOT]EMCMOT base_period_nsec=[EMCMOT]BASE_PERIOD servo_period_nsec=[EMCMOT]SERVO_PERIOD num_joints=[TRAJ]AXES

after:

# kinematics
loadrt pumakins
# trajectory planner
loadrt tp
# motion controller, get name and thread periods from ini file
loadrt [EMCMOT]EMCMOT base_period_nsec=[EMCMOT]BASE_PERIOD servo_period_nsec=[EMCMOT]SERVO_PERIOD num_joints=[TRAJ]AXES tp=tp kins=pumakins
ArcEye commented 6 years ago

Comment by mhaberler Sun Feb 22 06:16:22 2015


it's just 107 files after all:

 find configs/ -name '*.hal' -print|xargs grep EMCMOT|grep -v tp=tp|cut -d ':' -f1
ArcEye commented 6 years ago

Comment by luminize Sun Feb 22 09:49:00 2015


When you need a testing gnome, give a yell and I'll rebase onto your branch and run my machine

On 22 Feb 2015, at 07:16, Michael Haberler notifications@github.com wrote:

it's just 107 files after all:

find configs/ -name '*.hal' -print|xargs grep EMCMOT|grep -v tp=tp|cut -d ':' -f1 — Reply to this email directly or view it on GitHub.

ArcEye commented 6 years ago

Comment by mhaberler Sun Feb 22 11:17:34 2015


Actually I'd appreciate that very much, the bbot seems to be wedged

the https://github.com/mhaberler/machinekit/tree/vtable-tp-and-kins-try2 branch should be up-to-date relative to master

the only change you need for your config is the one mentioned above: loadrt tp, and add the tp=tp kins= incantation to the loadrt motmod line

ArcEye commented 6 years ago

Comment by yishinli Wed Mar 25 14:18:56 2015


Do you have an example HAL file that loads more than 1 tp? I'd like to learn how to instantiate 2 tps in one machine. Thanks.

ArcEye commented 6 years ago

Comment by mhaberler Wed Mar 25 23:20:42 2015


Hi Yishin,

I admit I am late on documentation but the gist is this:

summary: build a separate tp module which does a hal_init() but retain the code from tpmain.c (hal_export_vtable..) in the using code, refer to the vtable by name and API version, - just grep for vtable in the emc/motion directory to see how its imported

hope this gets the idea across, let me know if you need a more detailed example

good luck, - Michael

ArcEye commented 6 years ago

Comment by mhaberler Thu Mar 26 07:05:26 2015


also, this vtable example might help: https://github.com/machinekit/machinekit/tree/master/src/hal/vtable-example

ArcEye commented 6 years ago

Comment by yishinli Thu Mar 26 07:15:25 2015


Hi Michael,

I'm working on this. And, is studying the github work-flow. Will inform you if I get any progress.

Regards,

Yishin

ARAIS ROBOT TECHNOLOGY www.araisrobo.com TEL: +886-2-8919-1239

On Thu, Mar 26, 2015 at 3:05 PM, Michael Haberler notifications@github.com wrote:

also, this vtable example might help: https://github.com/machinekit/machinekit/tree/master/src/hal/vtable-example

— Reply to this email directly or view it on GitHub https://github.com/machinekit/machinekit/issues/476#issuecomment-86364838 .

ArcEye commented 6 years ago

Comment by yishinli Thu Mar 26 10:35:22 2015


In order to have 2 independent TPs for 1 machine, I will need to load the following modules:

Is my understanding correct? -Yishin

ArcEye commented 6 years ago

Comment by mhaberler Thu Mar 26 12:13:33 2015


we need to fix the latter beforehand; note also the linuxcnc using layer (task etc) has NO idea that there could be more than one motion (maybe some hack with SHMKEY is possible)

ArcEye commented 6 years ago

Comment by mhaberler Thu Mar 26 13:27:10 2015


I guess that wasnt totally helpful ;) what you CAN do is use several different TP's and kins from motion!

ArcEye commented 6 years ago

Comment by yishinli Thu Mar 26 14:06:12 2015


Thanks, I believe that is the solution. What I'm going to do is identical to one of the application stated on the Machinekit Blog Loadable Trajectory Modules.

Maybe your robot arm also has a gimbal mounted camera you want to control independently