Codice Lua
Codice Lua
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)
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