user interface and several events

Typically: "How do I... ", "How can I... " questions
Post Reply
thoriqsalafi
Posts: 3
Joined: 05 Mar 2014, 04:30

user interface and several events

Post by thoriqsalafi » 11 Mar 2014, 03:50

Hi,

I want to create this scenario :
when I click "head nod" button in my UI, the asti robot head will nod, and when I click the "wave hand" the asti robot will stop the head nod and start to wave its hand.

how to create such scenario? do I need to have loop in threaded script? or can i just create threaded script?, how to change the events (e.g. from wave hand to head nod after clicking the button?)

thank you!

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

Re: user interface and several events

Post by coppelia » 11 Mar 2014, 11:02

Hello,

you could have a threaded child script similar to following one:

Code: Select all

-- Retrieve handles, etc.

-- Now the main loop:
while (simGetSimulationState()~=sim_simulation_advancing_abouttostop) do 
	command=simGetIntegerSignal('astiCmd')
	if (command) then
		simClearIntegerSignal('astiCmd')$
		if (command==1) then
			-- Write your head nodding code here:
			-- you would typically have a table containing the neck joint positions to apply
			-- e.g.
			neckMovement={0,0.1,0.2,0.1,0,-0.1,-0.2,-0.1,0}
			for i=1,#neckMopvement,1 do
				simSetJointTargetPosition(neckJointHandle,neckMovement[i])
				simSwitchThread() -- suspend this thread until next simulation pass has started
			end
			-- above example is extremely simple and just for illustration
		end
		if (command==2) then
			-- Write your hand waving code here:

		end
	end
	simSwitchThread() -- suspend this thread until next simulation pass has started
end
Then, from another child script, you can set a signal indicating which command you want to be payed-back: simSetIntegerSignal('astiCmd',2) (command for waving the hand).

You can do exactly the same from an external application then, using the remote API for instance: simxSetIntegerSignal

Cheers

Post Reply