0% found this document useful (0 votes)
19 views1 page

Codice Lua

Uploaded by

Giacomo Reale
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views1 page

Codice Lua

Uploaded by

Giacomo Reale
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

--Questo script riceve i dati via seriale da RC2ARDUINO2ch.

ino
function sysCall_init()
-- do some initialization here

motorHandlesFL=sim.getObject('./front_left_wheel')
motorHandlesFR=sim.getObject('./front_right_wheel')
motorHandlesBR=sim.getObject('./back_right_wheel')
motorHandlesBL=sim.getObject('./back_left_wheel')

port="\\\\.\\COM4"
baudrate=9600
serial=sim.serialOpen(port,baudrate)

--acquisisce i primi dati emessi nelle fasi iniziali dalla radio


for i = 1, 20 do
str=sim.serialRead(serial,100,true,'\n',100)
end
k=5
end

function sysCall_actuation()
-- put your actuation code here

str=sim.serialRead(serial,100,true,'\n',100)
-- x, y, z = str:match("([^,]+),([^,]+),([^,]+)")
x, y = str:match("([^,]+),([^,]+)")
x = tonumber(x)
y = tonumber(y)
--z = tonumber(z)
-- print(type(valore))
x = x *3.14159/180
y = y *3.14159/180
sim.setJointTargetVelocity(motorHandlesFL, k*(y+x))
sim.setJointTargetVelocity(motorHandlesFR, k*(y-x))
sim.setJointTargetVelocity(motorHandlesBR, k*(y-x))
sim.setJointTargetVelocity(motorHandlesBL, k*(y+x))

print(x,y)
--print(x)

end

function sysCall_sensing()
-- put your sensing code here
end

function sysCall_cleanup()
-- do some clean-up here
end

-- See the user manual or the available code snippets for additional callback
functions and details

You might also like