Stop Conveyor

Typically: "How do I... ", "How can I... " questions
Post Reply
hieuhu
Posts: 3
Joined: 13 Jun 2024, 11:58

Stop Conveyor

Post by hieuhu »

Hi,
I am student and complety new with CoppliaSim(4.6.0)
I am having trouble stopping the conveyor when proximity sensor detect box. When I drag the conveyor into the workspace, the conveyor's icon in the scene hierarchy only attaches the customization script. I have tried uncommenting a few lines of code in customization script like this:

Code: Select all

--lua

sim=require'sim'

conveyor=require('conveyor_customization-2')

-- To command the conveyor externally or from another script, simply do:
--
 sim.writeCustomTableData(conveyorHandle,'__ctrl__',{vel=0.1}) -- vel. ctrl
--
-- or:
--
 sim.writeCustomTableData(conveyorHandle,'__ctrl__',{pos=0.1}) -- pos. ctrl
--
-- Its current state can be read with:
 local data=sim.readCustomTableData(conveyorHandle,'__state__')
and customization script is error.
I also try to put this code(1) in customization script when I have re-commented those line of code above:

Code: Select all

function sysCall_init()
    sensor=sim.getObject('Proximity_sensor')
end
function sysCall_actuation()
    beltVelocity=0.3
    if sim.readProximitySensor(sensor) > 0 then
        beltVelocity=0
    end
    sim.writeCustomTableData(sensor,'__ctrl__',{vel=beltVelocity})
end
between two line of code is:

Code: Select all

sim=require'sim'
and:

Code: Select all

conveyor=require('conveyor_customization-2')
so the script does not have any errors but conveyor doesn't stop.
I also try put those code(1) in child script but seem compiler don't understand

Code: Select all

sim.getObject('Proximity_sensor')
or similar API like this.
What should i do for stop conveyor when proximity sensor detect box?
Thank you!

fferri
Posts: 1297
Joined: 09 Sep 2013, 19:28

Re: Stop Conveyor

Post by fferri »

Make sure that:
  • the object to detect by the proximity sensor are flagged as Detectable
  • the object is still detected after the conveyor has stopped (velocity control is not instantaneous, it has an acceleration profile)
Following code works fine here:

Code: Select all

function sysCall_init()
    sim = require 'sim'
    proxSensor = sim.getObject '..'
    conveyor = sim.getObject '/conveyor'
end

function sysCall_actuation()
    local r, d, p, h, n = sim.readProximitySensor(proxSensor)
    sim.writeCustomTableData(conveyor, '__ctrl__', {vel = r > 0 and 0 or 0.05})
end

hieuhu
Posts: 3
Joined: 13 Jun 2024, 11:58

Re: Stop Conveyor

Post by hieuhu »

fferri wrote: 14 Jun 2024, 10:50 Make sure that:
  • the object to detect by the proximity sensor are flagged as Detectable
  • the object is still detected after the conveyor has stopped (velocity control is not instantaneous, it has an acceleration profile)
Following code works fine here:

Code: Select all

function sysCall_init()
    sim = require 'sim'
    proxSensor = sim.getObject '..'
    conveyor = sim.getObject '/conveyor'
end

function sysCall_actuation()
    local r, d, p, h, n = sim.readProximitySensor(proxSensor)
    sim.writeCustomTableData(conveyor, '__ctrl__', {vel = r > 0 and 0 or 0.05})
end
It's already worked.
Thanks for your support

Post Reply