PyChrono: Methods For Presence Detection

50 views
Skip to first unread message

UnBoxerMulletMaster

unread,
Dec 13, 2021, 1:24:50 AM12/13/21
to ProjectChrono
Good day,

Is there any PyChrono implementations for simple presence detection? For example whenever an object passes through a space the "detector" is set true, and when an object leaves the space it returns false.

A practical of this detection example would be a box moving along a conveyor and being seen by a photocell as it approaches the next conveyor.

Regards,

Radu Serban

unread,
Dec 13, 2021, 2:20:19 AM12/13/21
to monox...@live.ca, ProjectChrono

There is no explicit support for this, also because this type of monitoring is quite application specific.  A couple of suggestions:

  1. If it is enough to monitor only a point on the object, you could implement your own “point in volume” check using the specific shape of your test volume. You may find some useful functions and algorithms in the chrono collision system (see ChCollisionUtilsPRIMS.cpp).

  2. If you want to use the actual collision shape of the object to trigger the detection, you can use the `NarrowphaseCallback` mechanism provided in Chrono.  See this example for an illustration.  The idea is to:
    1. Als create a collision shape for the “test volume” (you will need to create a body to carry that collision model – in your case likely the “ground” body).
    2. Implement and register a custom object of type `NarrowphaseCallback`.
    3. Intercept all reported collisions during the narrowphase (in the overridden OnNarrowphase() method of your narrowphase callback object).  At each time step, this method is called for all current collision pairs identified by the narrowphase algorithm.
    4. Identify if a particular collision involves the “test volume” and the desired object:

                                                                           i.      If yes, process information as desired and return false (so that this particular collision is discarded and does not generate contact forces).

                                                                         ii.      If no, simply return true (so that contact forces are generated).

 

Of course, all the above are in C++, but it should be straightforward to recode in Python as needed.  I don’t recall off the top of my head if we provided a Python wrapper for the NarrowphaseCallback mechanism;  let us know if that is not in place and we can easily add it.

 

--Radu

--
You received this message because you are subscribed to the Google Groups "ProjectChrono" group.
To unsubscribe from this group and stop receiving emails from it, send an email to projectchron...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/projectchrono/c76dc9a0-f354-4341-bcb8-701673b21c81n%40googlegroups.com.

Dan Negrut

unread,
Dec 13, 2021, 5:18:04 PM12/13/21
to monox...@live.ca, ProjectChrono

Another thing that can be tried is to simply use a camera sensor (from Chrono::Sensor) and do image processing on the video stream picked up by the camera sensor in Chrono.

This is if you are interested in automation, which seems to be the case from what you are saying. The purpose of C::Sensor is to enable this type of design (of automation, that is).

Dan

-------------------------------------------------

Mead Witter Foundation Professor

NVIDIA CUDA Fellow

Director, Wisconsin Applied Computing Center

Department of Mechanical Engineering

Department of Computer Science

University of Wisconsin - Madison

4150ME, 1513 University Avenue

Madison, WI 53706-1572

608 772 0914

608 265 2316 (Fax)

http://sbel.wisc.edu/

http://projectchrono.org/

http://homepages.cae.wisc.edu/~negrut

My calendar.

-------------------------------------------------

 

From: projec...@googlegroups.com <projec...@googlegroups.com>
Sent: Monday, December 13, 2021 1:20 AM
To: monox...@live.ca; ProjectChrono <projec...@googlegroups.com>
Subject: RE: [chrono] PyChrono: Methods For Presence Detection

 

There is no explicit support for this, also because this type of monitoring is quite application specific.  A couple of suggestions:

1.       If it is enough to monitor only a point on the object, you could implement your own “point in volume” check using the specific shape of your test volume. You may find some useful functions and algorithms in the chrono collision system (see ChCollisionUtilsPRIMS.cpp).

2.       If you want to use the actual collision shape of the object to trigger the detection, you can use the `NarrowphaseCallback` mechanism provided in Chrono.  See this example for an illustration.  The idea is to:

a.       Als create a collision shape for the “test volume” (you will need to create a body to carry that collision model – in your case likely the “ground” body).

b.       Implement and register a custom object of type `NarrowphaseCallback`.

c.       Intercept all reported collisions during the narrowphase (in the overridden OnNarrowphase() method of your narrowphase callback object).  At each time step, this method is called for all current collision pairs identified by the narrowphase algorithm.

d.       Identify if a particular collision involves the “test volume” and the desired object:

                                                                           i.      If yes, process information as desired and return false (so that this particular collision is discarded and does not generate contact forces).

                                                                         ii.      If no, simply return true (so that contact forces are generated).

 

Of course, all the above are in C++, but it should be straightforward to recode in Python as needed.  I don’t recall off the top of my head if we provided a Python wrapper for the NarrowphaseCallback mechanism;  let us know if that is not in place and we can easily add it.

 

--Radu

 

From: projec...@googlegroups.com <projec...@googlegroups.com> On Behalf Of monox...@live.ca
Sent: Monday, December 13, 2021 7:25 AM
To: ProjectChrono <projec...@googlegroups.com>
Subject: [chrono] PyChrono: Methods For Presence Detection

 

Good day,

 

Is there any PyChrono implementations for simple presence detection? For example whenever an object passes through a space the "detector" is set true, and when an object leaves the space it returns false.

 

A practical of this detection example would be a box moving along a conveyor and being seen by a photocell as it approaches the next conveyor.

 

Regards,

--
You received this message because you are subscribed to the Google Groups "ProjectChrono" group.
To unsubscribe from this group and stop receiving emails from it, send an email to projectchron...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/projectchrono/c76dc9a0-f354-4341-bcb8-701673b21c81n%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "ProjectChrono" group.
To unsubscribe from this group and stop receiving emails from it, send an email to projectchron...@googlegroups.com.

UnBoxerMulletMaster

unread,
Dec 13, 2021, 8:25:32 PM12/13/21
to ProjectChrono
Thank you for the direction Mr. Serban and Mr.Negrut, I will inform you of any progress in this regard.

Mr. Negrut, you are correct that i am interested in automation. The goal in this instance is to couple a simulation model with a PLC, using the simulated inputs(Photocells) and the physical model to stress test the controller logic. For an initial hack implementation I will probably use excel to transfer the variable data via OPC, however I am open to suggestions.

Perhaps the question I should be asking:  Is this an appropriate platform to be doing this? Typical PLC scan times for the process being tested range from 5-10 ms. If the simulation lags behind the scan time too much, i may be better off re-writing the logic in python and running it with the simulator.

Regards,

Dan Negrut

unread,
Dec 13, 2021, 10:00:13 PM12/13/21
to monox...@live.ca, ProjectChrono

Kind request – please educate me on what PLC and OPC and Photocells are and do.

At that point, I’ll try to help if I can.

Thanks.

Dan

P.S. Please don’t call me Mr. Negrut – that makes me feel even older than I already am. Dan will do  :-)

-------------------------------------------------

Bernard A. and Frances M. Weideman Professor

NVIDIA CUDA Fellow

Director, Wisconsin Applied Computing Center

Department of Mechanical Engineering

Department of Computer Science

University of Wisconsin - Madison

4150ME, 1513 University Avenue

Madison, WI 53706-1572

608 772 0914

UnBoxerMulletMaster

unread,
Dec 13, 2021, 10:42:15 PM12/13/21
to ProjectChrono
Hi Dan,

1) PLC stands for programmable logic controller. It is a computer used for industrial process control often programmed in ladder logic. Most and in some cases all of a process can be controlled by a PLC, specifically the run logic to motors for transfers on a assembly line or the commands to servo motors to position cutting tools or even firing discrete outputs like a hydraulic valve to lock a component in place.

2) Regarding OPC, Wikipedia copy-paste best describes it: "OPC specifies the communication of real-time plant data between control devices from different manufacturers"
Essentially in the case you can open an OPC connection between excel and the PLC for your target variable in the PLC.

For example what I have in mind: [Simulator] LaserA Is Blocked ----> [Excel] LaserA_PLCVariable = 1 -----> [PLC] LaserA = 1 ------------> Logic State Changes

3) A PhotoCell as a common detector used for presence detection in industrial processes, typically it changes state if the light it emits is interrupted or reflected by an object.
Attached is a photo of a Banner engineering T30. That specific model is typically used for closer detection, within a few inches.

Regards,
T30.JPG

Alessandro Tasora

unread,
Dec 14, 2021, 3:58:13 AM12/14/21
to UnBoxerMulletMaster, ProjectChrono
Hi

I have experience in industrial automation. In the past I dealt with OPC for an automation project. It is a very powerful communication layer - however if I could choose, I would stick with plain Ethercat or CAN fieldbus es, if hard-real time M2M communication is the only requirement. The OPC complication pays back when SCADA and HMI enter in the game, imho.

Anyway: if you really need OPC, one solution is that you directly generate OPC datagrams via a c++ API for OPC (if I remember, there are some open source libraries to this end) and send/receive them to your PLC, straight from a c++ simulator with Chrono. I do not see the need for passing through Excel... it could add latencies etc. 
By the way: if you do not use c++ and you prefer PyChrono, probably there are also OPC APIs for Python. 

A side note. Note that this would be soft real time, not hard real time (even more true if the simulation runs in Python). If you aim for a 5ms control frame with deterministic periodicity, it would be questionable - ok, "statistically" it may work. (A true hard RT with HIL, after all, would need that you run a true RT OS on your simulation side, ex. WxWorks, RTAI, etc., or that Win patch that Beckhoff delivers in TwinCAT for his PLC stuff. But this might be too far from your actual needs). 

A python or c++ simulator using Chrono can be faster than real time, hence allowing your HIL, but it depends on the complexity of the model. To give an idea: on a fast CPU I can run a robot model with a dozen of bodies and a dozen of joints with 1ms integration timesteps, faster than real-time. 
Hint: even in such a case, I would avoid a HIL tick of 1ms...I'd rather poll the fieldbus every 10ms so it is for example 10 integration time steps each fieldbus control frame (the in-between I/O could be just interpolated, extrapolated or ZOH) 

Thanks

Alessandro Tasora
University of Parma 




Reply all
Reply to author
Forward
0 new messages