Vector

SCONE is a software tool for predictive simulations of biomechanical movement. It uses OpenSim for modeling and simulation, and performs optimization using various control strategies, including feed-forward control, proprioceptic feedback control, and bal
POST REPLY
User avatar
Samane Amini
Posts: 100
Joined: Sun Jan 12, 2020 3:48 am

Vector

Post by Samane Amini » Fri Oct 06, 2023 2:22 am

Hi

I would like to create a vector in script lua like this: A = 0:0.1:1. It means A starts from 0 and stops at 1 by step 0.1. To create this vector in Lua, I used the following code:

A = {}

function init(model, par)
end

function update(model)
local start = 0
local stop = 1
local step = 0.1

for i = start, stop, step do
A[#A + 1] = i
end
end

function store_data(frame)
frame:set_value("A", A)
end

However, A is zero in Analysis plots as following picture. Would you help me how to correct it? (A is Rtime )
Screenshot 2023-10-06 112059d.png
Screenshot 2023-10-06 112059d.png (56.44 KiB) Viewed 253 times
Best

User avatar
Thomas Geijtenbeek
Posts: 432
Joined: Wed Mar 12, 2014 8:08 am

Re: Vector

Post by Thomas Geijtenbeek » Fri Oct 06, 2023 2:32 am

A seems to be a table, so you can't do frame:set_value("A", A).

function update(model, timestamp) is called every frame, so perhaps use timestamp to compute A?

If A is meant to be a constant array of increasing numbers, then you should compute it in init() and not in update().

User avatar
Samane Amini
Posts: 100
Joined: Sun Jan 12, 2020 3:48 am

Re: Vector

Post by Samane Amini » Fri Oct 06, 2023 2:44 am

Many Thanks Thomas for your quick reply.

May you tell me how to call A in form of a table?

I changed my main code to ask my question. In fact, I want to obtain the length of time vector at instance time. So by having time step, I create this vector to record time. In this case we have:

function update(model)

t = model:time()

local start = 0
local stop = t
local step = 0.01

for i = start, stop, step do
A[#A + 1] = i
end
end



Do you think my way is correct? or you have other solution?

Best

POST REPLY