## Sensors, scripts, tia portal. Small Project. Students need some help

Typically: "How do I... ", "How can I... " questions
Kaktuz
Posts: 2
Joined: 22 Jan 2019, 14:15

### Sensors, scripts, tia portal. Small Project. Students need some help

I am a student and we have a small project to do. Is there any person here that would help us:
- Tell me what sensor to use before and after barriers to detecting vehicles
- write the simplest script for handling these sensors (it opens when the vehicle comes up (it's nice if it waits 10 seconds).
it closes when the vehicle passes the sensor on the other side)
- in some way combine it with TIA portal and siemens 1200 so that you can simulate it ???
- write a script and use some screen (HMI) to display the number of vehicles leaving and entering?

We have a lot of projects, plus we are already doing our diplomas and this project, which was supposed to be a very easy way to graduate one subject . we would have mastered it but we would need more involvement for heavier items that's why we're looking for help.

our visualization:
https://zapodaj.net/3246475489563.png.html

For helpful people, we will try to return the favor as much as we can !! PLN / \$ ???

greetings

Justus
Posts: 42
Joined: 24 Jan 2017, 07:37

### Re: Sensors, scripts, tia portal. Small Project. Students need some help

Hi Kaktuz,

Maybe too late, but here goes:

1. Sensor: proximity sensor, ray type. Make sure the objects that need to be detected are detectable (Scene Object Properties -> Common -> Object special properties -> Detectable). Run the simulation and move the object in the sensor beam, the beam should then pulsate the light.
2. simple script: add a non-threaded child script to the barrier shape. In that script, read the sensor state using "sim.readProximitySensor". When active, move the barrier using "sim.setObjectPosition". Some logic will be needed to close it again after a while (use "sim.getSimulationTime"), something like a step program that you'll probably have written for Siemens PLCs should do nicely.
3. combine it with Siemens 1200: not easy, you'll need Siemens PLCSim Advanced + to write an interface between V-REP and the PLCSim. There are other ways (ethernet/serial/OPC-UA), but it is a project on its own. If this a project requirement, there are simulators better suited for the job (for instance: Emulate3D).
4. display the number of leaving/entering: in the barrier' child script, you can count the vehicles (make this counting part of your step program). Show the number by adding a banner to the barrier object ("sim.addBanner").

Good luck with the project!

Regards,
Justus

Kaktuz
Posts: 2
Joined: 22 Jan 2019, 14:15

### Re: Sensors, scripts, tia portal. Small Project. Students need some help

Can you check what I'm doing wrong with this script? I tried many options, check the revolutejoint and the beam from the barrier.

script:

function sysCall_actuation()
openUntil=0
currentTime=sim.getSimulationTime()

motor=sim.getObjectHandle("joint1")

if ((resF>0)or(resB>0))or(currentTime<openUntil) then
-- Opening...
if ((resF>0)or(resB>0)) then
openUntil=currentTime+5
end
sim.setJointTargetVelocity(motor,0.0)
else
sim.setJointTargetVelocity(motor,-2)
end
else
-- Closing...
sim.setJointTargetVelocity(motor,0.0)
else
sim.setJointTargetVelocity(motor,2)
end
----------------------
Associated object: cuboid (beam of barrier), maybe it should be a revolutejoint?

Our project for inspection:
https://we.tl/t-at5PuJUkdW

Justus
Posts: 42
Joined: 24 Jan 2017, 07:37

### Re: Sensors, scripts, tia portal. Small Project. Students need some help

Hi Kaktuz,

Multiple issues in your code/scene:
• the if/then block is not finished (it needed an extra "end")
• function sim.readProximitySensor needs the handle of the sensor object. So: resF=sim.readProximitySensor("Proximity_sensor0") should be: resF=sim.readProximitySensor(sim.getObjectHandle("Proximity_sensor0"))
• openUntil is set to 0 every simulation cycle, therefore this line: openUntil=currentTime+5 will not work for you.
• The cuboid shape attached to the joint is static, it cannot be moved by the joint. It must be a dynamic shape (Dynamic properties -> checkbox "Body is dynamic")
• Joint should be in Torque/force mode, with the motor enabled
Try setting the joint and shape properties as described above, and then try this sample code:

Code: Select all

function sysCall_actuation()

motor=sim.getObjectHandle("joint1")

if (resF>0)then
sim.setJointTargetVelocity(motor,2)
end
end

When the car reaches the barrier, it will move!

-Justus

EDIT one additional thing: start with the default script that is available when you add a child script. This script calls many other (mandatory) functions like sysCall_init() etc. If these are not available, it will not work (and you won't receive an error message!). A minimum script should look something like this:

Code: Select all

function sysCall_init()
end

function sysCall_actuation()

motor=sim.getObjectHandle("joint1")

if (resF>0)then
sim.setJointTargetVelocity(motor,2)
end
end

function sysCall_sensing()
end

function sysCall_cleanup()
end

Example scene: https://we.tl/t-6nMSjEps9Q