This is an example that uses a squat-to-stand motion to create synthetic accelerometer data, and then creates a tracking simulation to track the synthetic accelerometer signals. This example is used in hands-on workshops, and accordingly has blanks that users must fill in. See exampleSquatToStand_answers.m for a completed version.
3import exampleIMUTracking_helpers
as helpers
6sys.path.insert(1,
'../')
7import mocoPlotTrajectory
as plot
15model = helpers.getTorqueDrivenSquatToStandModel()
23helpers.addIMUFrame(model,
'torso',
24 osim.Vec3(0.08, 0.3, 0), osim.Vec3(0, 0.5*np.pi, 0.5*np.pi))
25helpers.addIMUFrame(model,
'femur_r',
26 osim.Vec3(0, -0.2, 0.05), osim.Vec3(0, 0, 0.5*np.pi))
27helpers.addIMUFrame(model,
'tibia_r', osim.Vec3(0, -0.2, 0.05),
28 osim.Vec3(0, 0, 0.5*np.pi))
33imuFramePaths = osim.StdVectorString()
34imuFramePaths.append( )
35imuFramePaths.append( )
36imuFramePaths.append( )
37osim.OpenSenseUtilities().addModelIMUs(model, imuFramePaths)
71problem.setTimeBounds( )
75problem.setStateInfo(
'/jointset/hip_r/hip_flexion_r/value', )
76problem.setStateInfo(
'/jointset/knee_r/knee_angle_r/value', )
77problem.setStateInfo(
'/jointset/ankle_r/ankle_angle_r/value', )
80problem.setStateInfoPattern(
'/jointset/.*/speed', )
86solver = study.initCasADiSolver()
87solver.set_num_mesh_intervals( )
88solver.set_optim_constraint_tolerance( )
89solver.set_optim_convergence_tolerance( )
91if not os.path.isfile(
'predictSolution.sto'):
108outputPaths = osim.StdVectorString()
110accelerometerSignals = osim.analyzeVec3(model,
111 predictSolution.exportToStatesTable(),
112 predictSolution.exportToControlsTable(),
118accelerometerSignals.setColumnLabels(imuFramePaths)
121helpers.plotAccelerationSignals(accelerometerSignals)
131tracking.setFramePaths( )
132tracking.setAccelerationReference( )
133tracking.setGravityOffset( )
134tracking.setExpressAccelerationsInTrackingFrames( )
141if not os.path.isfile(
'trackingSolution.sto'):
149plot.mocoPlotTrajectory(
'predictSolution.sto',
'trackingSolution.sto',
154trackingSolution = osim.MocoTrajectory(
'trackingSolution.sto')
155accelerometerSignalsTracking = osim.analyzeVec3(model,
156 trackingSolution.exportToStatesTable(),
157 trackingSolution.exportToControlsTable(),
159accelerometerSignalsTracking.setColumnLabels(imuFramePaths)
160helpers.plotAccelerationSignals(accelerometerSignals,
161 accelerometerSignalsTracking)