When trying to store a double value (with ~14 relevant digits) with a Lua signal, the corresponding function seems to be sim.setFloatSignal. However, the values seem to be truncated to 32-bit float values when using this.
A test code looks like this:
local testvar=simROS.getTime()
-- or something like: local testvar=123456789.123456
print(testvar)
sim.setFloatSignal("TestVar",testvar)
testvar=sim.getFloatSignal("TestVar")
print(testvar)
and returns:
1559031075,2268
1559031040
There does not seem to be a setDoubleSignal function. So there is currently no possibility to use signals with double-precision values !
Possible solutions: Implement a setDoubleSignal function (and corresponding functions), or let setFloatSignal work with double-precision values by default.
I suspect that the same problem occurs for sim.getFloatParamter (but have not tested it).
Meanwhile, does anybody know a workaround for this ?
Double values get truncated when sent by signal
Re: Double values get truncated when sent by signal
Hello,
you can use following:
But yes, it makes sense to have sim.setFloatSignal / sim.getFloatSignal use doubles internally, or to add sim.setDoubleSignal / sim.getDoubleSignal.
Cheers
you can use following:
Code: Select all
-- Set double signal:
local doubleValue=123.4567890123
sim.setStringSignal('myDoubleValue',sim.packDoubleTable({doubleValue}))
-- Retrieve double signal:
local str=sim.getStringSignal('myDoubleValue')
if str then
local retrievedDoubleValue=sim.unpackDoubleTable(str)[1]
end
Cheers