I think Greg Biegel wrote:
> 
> (defrule avgweight
>  (SmartCouch_LoadCellSensor1_MassEvent_Bean (mass ?mass1))
>  (SmartCouch_LoadCellSensor2_MassEvent_Bean (mass ?mass2))
>  (SmartCouch_LoadCellSensor3_MassEvent_Bean (mass ?mass3))
>  (SmartCouch_LoadCellSensor4_MassEvent_Bean (mass ?mass4))
> =>
>  (bind ?*totalweight* (+ ?mass1 ?mass2 ?mass3 ?mass4))
>  (bind ?*averageweight* (/ ?*totalweight* 4))
>  (bind ?*averageweight* (- ?*averageweight* 0.5))
> )
> 
> However, each bean is not necessarily updated between each firing of the
> engine (as each bean is updated individually, it calls Rete.run()). What I
> am worried about is that this rule will only fire if ALL beans have had
> their mass field updated since the last firing, so I am unable to get a
> current average weight reading to use in the LHS of other rules in the same
> firing. 

No, it will actually fire any time any one of them changes, so maybe
that's good enough.

Defqueries are tough in Jess 6. They get a lot easier in Jess 7. But
there are examples in section 2.9 of the manual. You'd want your query
to look like

(defquery all-sensors
  (SmartCouch_LoadCellSensor1_MassEvent_Bean)
  (SmartCouch_LoadCellSensor2_MassEvent_Bean)
  (SmartCouch_LoadCellSensor3_MassEvent_Bean)
  (SmartCouch_LoadCellSensor4_MassEvent_Bean))

and the function that used it would look something like

(deffunction average-weight ()
  (bind ?result (run-query all-sensors))
  (bind ?token (?result next))
  (bind ?sum 0)
  (foreach i (create$ 1 2 3 4)
    (bind ?sum (+ ?sum (fact-slot-value (?token fact ?i) mass))))
  (return (- (/ ?sum 4) 0.5)))



---------------------------------------------------------
Ernest Friedman-Hill  
Science and Engineering PSEs        Phone: (925) 294-2154
Sandia National Labs                FAX:   (925) 294-2234
PO Box 969, MS 9012                 [EMAIL PROTECTED]
Livermore, CA 94550         http://herzberg.ca.sandia.gov

--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own address!) List problems? Notify [EMAIL PROTECTED]
--------------------------------------------------------------------

Reply via email to