I've been trying a simple on-off control algorithm which uses spaar's mod.
The script is working fine as the debugging log shows, but the wheel does not respond to changes in the "tilt" variable regardless of whether it's in automatic mode or not. Suggestions?
Attached Files
control1.bsg

Code:
-- import unity engine refference and declare variables
import ('UnityEngine')
setPoint = 325.0 -- the angle at which the lever should bounce about
tilt = 0.0 -- the speed of the wheel (which is in automatic mode)
er = 0.0 -- the difference(called error in control theory) between the actual angle of the lever and the desired one (setPoint)
simStart = function ()
-- initialize variables at start of simulation
setPoint = 325.0
tilt = 0.0
er = 0.0
end
frame = function ()
-- first introduce controls for the setPoint so that it is adjustable during simulation
if (Input.GetKey(KeyCode.I)) then
setPoint = setPoint + 1
end
if (Input.GetKey(KeyCode.K)) then
setPoint = setPoint - 1
end
-- now set the starting block to act as a gyroscope sensor
gyro = GameObject.Find ('bgeL0')
coord = gyro.transform.eulerAngles
er = coord[2] - setPoint -- estimate error
if (er < 0.0) then tilt = 0.1 else tilt = 0.0 end -- if the error is below 0 then apply torque to the wheel
-- log the relevant variables
Debug.Log (coord[2])
Debug.Log (setPoint)
Debug.Log (er)
Debug.Log (tilt)
end
Attached Files
control1.bsg