I've achieved to control my model(a car) by a joystick, but I failed to correctly transfer it's data to a file.
In particular, I firstly defined a function to define my car's moving state:
Code: Select all
function current_moving(m)
local moving=nil
if(m==0) then
moving='wait'
elseif(m==1) then
moving='forward'
elseif(m==2) then
moving='back'
elseif(m==3) then
moving='turn_L'
elseif(m=4) then
moving='turn_R'
end
return moving
end
Code: Select all
if(axes[2]>0 and -250<rotAxes[3] and rotAxes[3]<250) then --back
axes[2]=-axes[2]/10000
sim.setJointTargetVelocity(leftJointDynamic,(linearVelocityLeft*axes[2]*v)/(s*wheelRadius))
sim.setJointTargetVelocity(rightJointDynamic,(linearVelocityRight*axes[2]*v)/(s*wheelRadius))
m=2
elseif(axes[2]<0 and -250<rotAxes[3] and rotAxes[3]<250) then -- forward
axes[2]=-axes[2]/10000
sim.setJointTargetVelocity(leftJointDynamic,(linearVelocityLeft*axes[2]*v)/(s*wheelRadius))
sim.setJointTargetVelocity(rightJointDynamic,(linearVelocityRight*axes[2]*v)/(s*wheelRadius))
m=1
elseif(0<rotAxes[3]) then --turn left
rotAxes[3]=rotAxes[3]/50000
sim.setJointTargetVelocity(leftJointDynamic,(linearVelocityLeft*rotAxes[3]*v)/(s*wheelRadius))
sim.setJointTargetVelocity(rightJointDynamic,-(linearVelocityRight*rotAxes[3]*v)/(s*wheelRadius))
m=3
elseif(rotAxes[3]<0) then --turn right
rotAxes[3]=rotAxes[3]/50000
sim.setJointTargetVelocity(leftJointDynamic,(linearVelocityLeft*rotAxes[3]*v)/(s*wheelRadius))
sim.setJointTargetVelocity(rightJointDynamic,-(linearVelocityRight*rotAxes[3]*v)/(s*wheelRadius))
m=4
elseif(axes[2]==0)then
m=0
end
nominalLinearVelocity) when I release the joystick(I think it means the axes[2]==0), but it can't record 'wait' to the file, it still wrote 'forward'. and when m=3, it didn't wrote 'turn left' but 'turn right'. I want to know what's wrong with my code. I've tried a lot of way, and I can't solve the problems, please help me! btw... my joystick type is PXN-2113 which can control with only one hand.
Cheers