SimMechanics states from Simulink state vector
[vector_mgr, mech_states] = mech_get_states(X, block)
[vector_mgr, mech_states] = mech_get_states(X, vectorMgr)
[vector_mgr, mech_states] = mech_get_states(X, block) returns a state vector manager object. The object's values reflect the SimMechanics™ states in the Simulink® state vector X for the SimMechanics machine containing block. The function also returns the mechanical states vector_mgr.X in mech_states.
[vector_mgr, mech_states] = mech_get_states(X, vectorMgr) extracts the mechanical states from the Simulink state vector X and returns them as an array of states assigned to vector_mgr.X.
The returned vector manager is an instance of the MECH.StateVectorMgr class, the same class as returned by the mech_stateVectorMgr function.
mech_get_states accepts two possible combinations of two inputs.
The Simulink state vector for your model. X must be compatible with your Simulink model.
A string or block handle specifying the absolute path of a block in the machine that you want to query.
A mechanical state vector manager object of the MECH.StateVectorMgr class.
mech_get_states produces one or two outputs.
An instance of the MECH.StateVectorMgr object class whose values reflect the mechanical state of the model.
A vector of the mechanical state values. Identical to vector_mgr.X, if you use the first form of the function.
Simulate a Stewart platform model for 10 seconds, capturing the model state over the entire simulation:
simOut = sim('mech_stewart_trajectory','StopTime','10', ... 'SaveState','on','StateSaveName','xout'); xout = simOut.get('xout');
Populate the state vector manager with this model's final state:
stewartStateVectorMgr = mech_get_states(xout(end,:), ... 'mech_stewart_trajectory/Plant/Machine Environment');