How can I change gradually the coordinates of the target dummy to move an army robot KUKA(LRB4p)?

Typically: "How do I... ", "How can I... " questions
Post Reply
elizakh
Posts: 29
Joined: 20 Feb 2021, 13:27

How can I change gradually the coordinates of the target dummy to move an army robot KUKA(LRB4p)?

Post by elizakh »

Hi everyone,
I’m trying to programme a painting robot. For that I’m using a KUKA robot (LRB4p) and a Paint Nozzle.
The robot has to paint a wall and for that I’m trying to do the movement with IK plugin. I’ve followed all the steps that are specified in the tutorial (and after that I’ve some errors during the simulation) but I don’t know how can I change the position of the target dummy gradually and obviously, the robot has to follow the target dummy. So, in resume, I want to move the robot specifying the coordinates (for example: move(robot,pos1) , move(robot,pos2) ) and I want to specify pos1, pos2,...

Thanks in advance

coppelia
Site Admin
Posts: 10360
Joined: 14 Dec 2012, 00:25

Re: How can I change gradually the coordinates of the target dummy to move an army robot KUKA(LRB4p)?

Post by coppelia »

Hello,

in order to gradually move an object, simple gradually change its position. E.g. the simplest would be to do something like:

Code: Select all

function sysCall_init()
    h=sim.getObjectHandle('myObject')
    v=0.1 -- 0.1 meters per second
end

function sysCall_actuation()
    local dt=sim.getSimulationTimeStep()
    local p=sim.getObjectPosition(h,-1)
    p[1]=p[1]+v*dt
    sim.setObjectPosition(h,-1,p)
end
Obviously there are many other more sophisticated ways of moving an object, e.g. via a maximum velocity and/or acceleration value. For that, have a look at the Reflexxes Motion Library API functions.

You can also move an object along a path in various ways. Check also the following demo scenes:

scenes/trajectoryAndMotion/reflexxesMotionLibraryExamples.ttt
scenes/kinematics/smoothMovementsInFkAndIk.ttt
scenes/movingAlongAPath.ttt
scenes/trajectoryAndMotion/pathToTrajectory.ttt


Cheers

elizakh
Posts: 29
Joined: 20 Feb 2021, 13:27

Re: How can I change gradually the coordinates of the target dummy to move an army robot KUKA(LRB4p)?

Post by elizakh »

Hi,
thanks for your reply.

So in this case if i want to use sim.moveToPose, I've to define two dummies (Target and tip) and now use the function?
Or simply I can define the currentPose by sim.getObjectPosition and define the targetPose with the coordinates or a metric distance(in this case I don't know how can I implement that).
And finally, I don't understand the use of the callback function and how I can define that?

My goal is to define a painting robot (an army robot with a paint nozzle) and specify 4 positions via coordinates, but I'm a little confused because I saw many options to do that and I don't know if there's an easy way to do it or not.

Thanks in advance
Cheers!

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

Re: How can I change gradually the coordinates of the target dummy to move an army robot KUKA(LRB4p)?

Post by fferri »

You can define the pose numerically, or by a dummy (then use sim.getObjectPose to get the numerical value).

You can omit the metric if not needed.

Here's a simple example of using sim.moveToPose (the code must be in a coroutine because the function will block until motion is complete):

Code: Select all

function sysCall_init()
    corout=coroutine.create(coroutineMain)
end

function sysCall_actuation()
    if coroutine.status(corout)~='dead' then
        local ok,errorMsg=coroutine.resume(corout)
        if errorMsg then
            error(debug.traceback(corout,errorMsg),2)
        end
    end
end

function coroutineMain()
    local obj=sim.getObjectHandle('Cuboid')
    local flags=-1
    local currentPose=sim.getObjectPose(sim.getObjectHandle('StartDummy'),-1)
    local maxVel={0.2,0.2,0.2,0.1}
    local maxAccel={0.1,0.1,0.1,0.05}
    local maxJerk={0.1,0.1,0.1,0.05}
    local targetPose=sim.getObjectPose(sim.getObjectHandle('GoalDummy'),-1)
    local function callback(currentPose,currentVel,currentAccel,auxData)
        sim.setObjectPose(obj,-1,currentPose)
    end
    endPose,timeLeft=sim.moveToPose(flags,currentPose,maxVel,maxAccel,maxJerk,targetPose,callback)
end

elizakh
Posts: 29
Joined: 20 Feb 2021, 13:27

Re: How can I change gradually the coordinates of the target dummy to move an army robot KUKA(LRB4p)?

Post by elizakh »

Hi,

thanks for your response.

I've another trouble with IK in CoppeliaSim V2.0.

I've followed all the steps of this tutorial: https://www.coppeliarobotics.com/helpFi ... torial.htm to do the IK with an UR5, but when I run the simulation, appears a dialog with "IK solver failed" and the UR5 breaks into pieces, and I don't know what is wrong.
I set all the joints in passive mode, and created Tip and Target. It's necessary to link them also like in CoppeliaSim V4.1?

My code is:

Code: Select all

function sysCall_init()
    corout=coroutine.create(coroutineMain)
    
    -- Build a kinematic chain and 2 IK groups (undamped and damped) inside of the IK plugin environment,
    -- based on the kinematics of the robot in the scene:
    -- There is a simple way, and a more elaborate way (but which gives you more options/flexibility):

    -- Simple way:
    local simBase=sim.getObjectHandle('UR5')
    local simTip=sim.getObjectHandle('Tip')
    local simTarget=sim.getObjectHandle('Target')
    -- create an IK environment:
    ikEnv=simIK.createEnvironment()
    -- create an IK group: 
    ikGroup_undamped=simIK.createIkGroup(ikEnv)
    -- set its resolution method to undamped: 
    simIK.setIkGroupCalculation(ikEnv,ikGroup_undamped,simIK.method_pseudo_inverse,0,6)
    -- create an IK element based on the scene content: 
    simIK.addIkElementFromScene(ikEnv,ikGroup_undamped,simBase,simTip,simTarget,simIK.constraint_pose)
    -- create another IK group: 
    ikGroup_damped=simIK.createIkGroup(ikEnv)
    -- set its resolution method to damped: 
    simIK.setIkGroupCalculation(ikEnv,ikGroup_damped,simIK.method_damped_least_squares,1,99)
    -- create an IK element based on the scene content: 
    simIK.addIkElementFromScene(ikEnv,ikGroup_damped,simBase,simTip,simTarget,simIK.constraint_pose) 
   
end

function sysCall_actuation()
    if coroutine.status(corout)~='dead' then
        local ok,errorMsg=coroutine.resume(corout)
        if errorMsg then
            error(debug.traceback(corout,errorMsg),2)
        end
    end
 -- Simple way:
    -- try to solve with the undamped method:
    if simIK.applyIkEnvironmentToScene(ikEnv,ikGroup_undamped,true)==simIK.result_fail then 
        -- the position/orientation could not be reached.
        -- try to solve with the damped method:
        simIK.applyIkEnvironmentToScene(ikEnv,ikGroup_damped)
        -- We display a IK failure report message: 
        if not ikFailedReportHandle then 
            ikFailedReportHandle=sim.displayDialog("IK failure report","IK solver failed.",
                sim.dlgstyle_message,false,"",nil,{1,0.7,0,0,0,0})
        end
    else
        if ikFailedReportHandle then
        	-- We close any report message about IK failure:
            sim.endDialog(ikFailedReportHandle) 
            ikFailedReportHandle=nil
        end
    end   
    
    
end

-- This is a threaded script, and is just an example!

function coroutineMain()
 
end

function sysCall_cleanup()
	-- erase the IK environment: 
    simIK.eraseEnvironment(ikEnv) 
end 
Thanks in advance

coppelia
Site Admin
Posts: 10360
Joined: 14 Dec 2012, 00:25

Re: How can I change gradually the coordinates of the target dummy to move an army robot KUKA(LRB4p)?

Post by coppelia »

The probable reason why the robot is falling apart: by default, that robot model is dynamically enabled. So either you leave the joints in force/torque mode, or you simply set the whole model as model is not dynamic in the model dialog.

Cheers

Post Reply