Hi Kirk.

The way you have to think about a time-consuming task in a HAL component
is different than the way you would think about it in a script or in
ladder rungs.

I have enclosed an example below that does some of what you need, though
I am sure it will still require adaptation to your situation.

Both turret.comp and turret-test.comp have to take actions based on what
happened far in the past.  They do it in a similar way: by using a
parameter to keep track of the time until this action should be taken
(wait_time_left and turn_time_left).  A few 'if's will manage
wait_time_left properly:
 . If the action should be postponed, then set wait_time_left to wait_time
 . Otherwise, if wait_time_left is less than period, take the action.
 . Otherwise, reduce wait_time_left by period.

I hope that if you still want to do this with comp, my examples here can
be helpful to you.

- turret.comp ----------------------------------------------------------
component turret "Turret control for Kirk Wallace";
pin in u32 desired_index "The index to turn the turret to";
pin in u32 current_index "The current index the turret is turned to";
pin out bit turn "TRUE when the turret should turn";
pin out bit stable
    "TRUE when the turret is stable at desired_index and not turning";
param rw u32 wait_time
    "Number of nanoseconds it takes for the turret to become stable";
param r u32 wait_time_left
    "Number of nanoseconds left until the turret is stable";
function _ nofp;
;;
MODULE_LICENSE("GPL");
FUNCTION(_) {
    if(desired_index != current_index) {
        turn = 1;
        stable = 0;
        wait_time_left = wait_time;
    } else {
        turn = 0;
        if(wait_time_left < period) {
            wait_time_left = 0;
            stable = 1;
        } else {
            wait_time_left -= period;
        }
    }
}
- turret-test.comp -----------------------------------------------------
component turret_test "Turret test component";
pin out u32 position "Current turret slot";
pin in bit turn "TRUE to turn turret";
param rw u32 turn_time "Time to turn from one slot to the next";
param r u32 turn_time_left "Time left during this turn";
param rw u32 slot_count "Number of turret slots";
function _ nofp;
;;
MODULE_LICENSE("GPL");
FUNCTION(_) {
    if(turn) {
        if(turn_time_left < period) {
            position = (position + 1) % slot_count;
            turn_time_left = turn_time;
        } else {
            turn_time_left -= period;
        }
    }
}
- turret-test.hal ------------------------------------------------------
# Run this with 'halrun -I' then interactively set turret.0.desired-index
# and watch the pins and params in halscope
loadrt threads name1=servo period1=1000000
loadrt turret
loadrt turret_test
setp turret-test.0.slot-count 4
setp turret-test.0.turn-time 500000000

setp turret.0.wait-time 2000000000

addf turret-test.0 servo
addf turret.0 servo

net turret-turn turret.0.turn => turret-test.0.turn
net turret-slot turret-test.position -> turret.0.desired-index

start
------------------------------------------------------------------------

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Emc-users mailing list
Emc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/emc-users

Reply via email to