OpenSim3.3 GUI flashed!

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
ruoshi wen
Posts: 32
Joined: Sat Jun 17, 2017 7:44 pm

OpenSim3.3 GUI flashed!

Post by ruoshi wen » Sun Jul 23, 2017 6:57 am

I write a model and here's my code.

Code: Select all

#include "McKibbenActuator.h"
#include <OpenSim/OpenSim.h>

using namespace OpenSim;
using namespace SimTK;

//______________________________________________________________________________
/**
 * First exercise: create a model that does nothing. 
 */
int main()
{
	try {
		// Create an OpenSim model and set its name
		Model arm;
		arm.setName("armSimple");

		// Get a reference to the model's ground body
		OpenSim::Body& ground = arm.getGroundBody();

		//Add display geometry to the ground to visualize in the GUI
		ground.addDisplayGeometry("ground_ribs.vtp");
		ground.addDisplayGeometry("ground_spine.vtp");
		ground.addDisplayGeometry("ground_skull.vtp");
		ground.addDisplayGeometry("ground_jaw.vtp");
		ground.addDisplayGeometry("ground_r_clavicle.vtp");
		ground.addDisplayGeometry("ground_scapula.vtp");
		//Save the model to a file

		//Specify properties of humurus
		double humurusMass = 1.99757;
		Vec3 humurusMassCenter(0.01806404, -0.14014073, -0.01274600);
		SimTK::Inertia humurusInertia(0.01227763,0.00255133, 0.01257888,-0.00034741, -0.00023250, 0.00122930 );

		// Create a new block body with specified properties
		OpenSim::Body *humurus = new OpenSim::Body("humurus", humurusMass, humurusMassCenter, humurusInertia);

		// Add display geometry to the block to visualize in the GUI
		humurus->addDisplayGeometry("humurus.vtp");


		double ulnaMass = 1.10530000;
		Vec3 ulnaMassCenter(0.00971783, -0.09595089, 0.02428600);
		SimTK::Inertia ulnaInertia(0.00541309, 0.00115318, 0.00494361, 0.00031686, -0.00007615, 0.00109169);

		// Create a new block body with specified properties
		OpenSim::Body *ulna = new OpenSim::Body("ulna", ulnaMass, ulnaMassCenter, ulnaInertia);

		// Add display geometry to the block to visualize in the GUI
	    ulna->addDisplayGeometry("ulna.vtp");



		// Create a new custom joint with 6 DoF(coordinates) between the humurus and ulna bodies


		Vec3 locationInParent(0.00610000, - 0.29040000, - 0.01230000), orientationInParent(0), locationInBody(0), orientationInBody(0);
	    FreeJoint *elbow = new FreeJoint("elbow", *humurus, locationInParent, orientationInParent, *ulna, locationInBody, orientationInBody,false);
		// Get a reference to the coordinate set (6 degrees-of-freedom) between the block and ground bodies
		CoordinateSet& jointCoordinateSet = elbow->upd_CoordinateSet();

		// Set the angle and position ranges for the coordinate set (SimTK:: prefix not actually needed here)
		double angleRange[2] = { -SimTK::Pi / 2, SimTK::Pi / 2 };
		double positionRange[2] = { -1, 1 };

		jointCoordinateSet[0].setRange(angleRange);
		jointCoordinateSet[1].setRange(angleRange);
		jointCoordinateSet[2].setRange(angleRange);
		jointCoordinateSet[3].setRange(positionRange);
		jointCoordinateSet[4].setRange(positionRange);
		jointCoordinateSet[5].setRange(positionRange);

        McKibbenActuator *actuator = new McKibbenActuator("humurus", "ulna");


		arm.addBody(humurus);
		arm.addBody(ulna);
		arm.print("armSimple_model.osim");

		

	}
    catch (OpenSim::Exception ex)
    {
        std::cout << ex.getMessage() << std::endl;
        return 1;
    }
    catch (std::exception ex)
    {
        std::cout << ex.what() << std::endl;
        return 1;
    }
    catch (...)
    {
        std::cout << "UNRECOGNIZED EXCEPTION" << std::endl;
        return 1;
    }

    std::cout << "OpenSim example completed successfully.\n";
	std::cin.get();
	return 0;
}
After I run the .exe , an .osim is generated.
When I try to open the .osim file in OpenSim3.3 GUI, the GUI just flashed and I don't know why.
Also, I installed the OpenSim3.3 on Win7.

Hope to get some help from you.
Thanks!
Best,
Ruoshi Wen

User avatar
ruoshi wen
Posts: 32
Joined: Sat Jun 17, 2017 7:44 pm

Re: OpenSim3.3 GUI flashed!

Post by ruoshi wen » Sun Jul 23, 2017 7:01 am

The .osim is as follows.

Code: Select all

<?xml version="1.0" encoding="UTF-8" ?>
<OpenSimDocument Version="30000">
	<Model name="armSimple">
		<credits>Frank Anderson, Peter Loan, Ayman Habib, Ajay Seth, Michael Sherman</credits>
		<publications>Unassigned</publications>
		<length_units>meters</length_units>
		<force_units>N</force_units>
		<!--Acceleration due to gravity.-->
		<gravity> 0 -9.80665 0</gravity>
		<!--Bodies in the model.-->
		<BodySet>
			<objects>
				<Body name="ground">
					<mass>0</mass>
					<mass_center> 0 0 0</mass_center>
					<inertia_xx>1</inertia_xx>
					<inertia_yy>1</inertia_yy>
					<inertia_zz>1</inertia_zz>
					<inertia_xy>0</inertia_xy>
					<inertia_xz>0</inertia_xz>
					<inertia_yz>0</inertia_yz>
					<!--Joint that connects this body with the parent body.-->
					<Joint />
					<VisibleObject>
						<!--Set of geometry files and associated attributes, allow .vtp, .stl, .obj-->
						<GeometrySet>
							<objects>
								<DisplayGeometry>
									<!--Name of geometry file .vtp, .stl, .obj-->
									<geometry_file>ground_ribs.vtp</geometry_file>
									<!--Color used to display the geometry when visible-->
									<color> 1 1 1</color>
									<!--Name of texture file .jpg, .bmp-->
									<texture_file />
									<!--in body transform specified as 3 rotations (rad) followed by 3 translations rX rY rZ tx ty tz-->
									<transform> -0 0 -0 0 0 0</transform>
									<!--Three scale factors for display purposes: scaleX scaleY scaleZ-->
									<scale_factors> 1 1 1</scale_factors>
									<!--Display Pref. 0:Hide 1:Wire 3:Flat 4:Shaded-->
									<display_preference>4</display_preference>
									<!--Display opacity between 0.0 and 1.0-->
									<opacity>1</opacity>
								</DisplayGeometry>
								<DisplayGeometry>
									<!--Name of geometry file .vtp, .stl, .obj-->
									<geometry_file>ground_spine.vtp</geometry_file>
									<!--Color used to display the geometry when visible-->
									<color> 1 1 1</color>
									<!--Name of texture file .jpg, .bmp-->
									<texture_file />
									<!--in body transform specified as 3 rotations (rad) followed by 3 translations rX rY rZ tx ty tz-->
									<transform> -0 0 -0 0 0 0</transform>
									<!--Three scale factors for display purposes: scaleX scaleY scaleZ-->
									<scale_factors> 1 1 1</scale_factors>
									<!--Display Pref. 0:Hide 1:Wire 3:Flat 4:Shaded-->
									<display_preference>4</display_preference>
									<!--Display opacity between 0.0 and 1.0-->
									<opacity>1</opacity>
								</DisplayGeometry>
								<DisplayGeometry>
									<!--Name of geometry file .vtp, .stl, .obj-->
									<geometry_file>ground_skull.vtp</geometry_file>
									<!--Color used to display the geometry when visible-->
									<color> 1 1 1</color>
									<!--Name of texture file .jpg, .bmp-->
									<texture_file />
									<!--in body transform specified as 3 rotations (rad) followed by 3 translations rX rY rZ tx ty tz-->
									<transform> -0 0 -0 0 0 0</transform>
									<!--Three scale factors for display purposes: scaleX scaleY scaleZ-->
									<scale_factors> 1 1 1</scale_factors>
									<!--Display Pref. 0:Hide 1:Wire 3:Flat 4:Shaded-->
									<display_preference>4</display_preference>
									<!--Display opacity between 0.0 and 1.0-->
									<opacity>1</opacity>
								</DisplayGeometry>
								<DisplayGeometry>
									<!--Name of geometry file .vtp, .stl, .obj-->
									<geometry_file>ground_jaw.vtp</geometry_file>
									<!--Color used to display the geometry when visible-->
									<color> 1 1 1</color>
									<!--Name of texture file .jpg, .bmp-->
									<texture_file />
									<!--in body transform specified as 3 rotations (rad) followed by 3 translations rX rY rZ tx ty tz-->
									<transform> -0 0 -0 0 0 0</transform>
									<!--Three scale factors for display purposes: scaleX scaleY scaleZ-->
									<scale_factors> 1 1 1</scale_factors>
									<!--Display Pref. 0:Hide 1:Wire 3:Flat 4:Shaded-->
									<display_preference>4</display_preference>
									<!--Display opacity between 0.0 and 1.0-->
									<opacity>1</opacity>
								</DisplayGeometry>
								<DisplayGeometry>
									<!--Name of geometry file .vtp, .stl, .obj-->
									<geometry_file>ground_r_clavicle.vtp</geometry_file>
									<!--Color used to display the geometry when visible-->
									<color> 1 1 1</color>
									<!--Name of texture file .jpg, .bmp-->
									<texture_file />
									<!--in body transform specified as 3 rotations (rad) followed by 3 translations rX rY rZ tx ty tz-->
									<transform> -0 0 -0 0 0 0</transform>
									<!--Three scale factors for display purposes: scaleX scaleY scaleZ-->
									<scale_factors> 1 1 1</scale_factors>
									<!--Display Pref. 0:Hide 1:Wire 3:Flat 4:Shaded-->
									<display_preference>4</display_preference>
									<!--Display opacity between 0.0 and 1.0-->
									<opacity>1</opacity>
								</DisplayGeometry>
								<DisplayGeometry>
									<!--Name of geometry file .vtp, .stl, .obj-->
									<geometry_file>ground_scapula.vtp</geometry_file>
									<!--Color used to display the geometry when visible-->
									<color> 1 1 1</color>
									<!--Name of texture file .jpg, .bmp-->
									<texture_file />
									<!--in body transform specified as 3 rotations (rad) followed by 3 translations rX rY rZ tx ty tz-->
									<transform> -0 0 -0 0 0 0</transform>
									<!--Three scale factors for display purposes: scaleX scaleY scaleZ-->
									<scale_factors> 1 1 1</scale_factors>
									<!--Display Pref. 0:Hide 1:Wire 3:Flat 4:Shaded-->
									<display_preference>4</display_preference>
									<!--Display opacity between 0.0 and 1.0-->
									<opacity>1</opacity>
								</DisplayGeometry>
							</objects>
							<groups />
						</GeometrySet>
						<!--Three scale factors for display purposes: scaleX scaleY scaleZ-->
						<scale_factors> 1 1 1</scale_factors>
						<!--transform relative to owner specified as 3 rotations (rad) followed by 3 translations rX rY rZ tx ty tz-->
						<transform> -0 0 -0 0 0 0</transform>
						<!--Whether to show a coordinate frame-->
						<show_axes>false</show_axes>
						<!--Display Pref. 0:Hide 1:Wire 3:Flat 4:Shaded Can be overriden for individual geometries-->
						<display_preference>4</display_preference>
					</VisibleObject>
					<WrapObjectSet>
						<objects />
						<groups />
					</WrapObjectSet>
				</Body>
				<Body name="humurus">
					<mass>1.99757</mass>
					<mass_center> 0.018064 -0.140141 -0.012746</mass_center>
					<inertia_xx>0.01227763</inertia_xx>
					<inertia_yy>0.00255133</inertia_yy>
					<inertia_zz>0.01257888</inertia_zz>
					<inertia_xy>-0.00034741</inertia_xy>
					<inertia_xz>-0.0002325</inertia_xz>
					<inertia_yz>0.0012293</inertia_yz>
					<!--Joint that connects this body with the parent body.-->
					<Joint />
					<VisibleObject>
						<!--Set of geometry files and associated attributes, allow .vtp, .stl, .obj-->
						<GeometrySet>
							<objects>
								<DisplayGeometry>
									<!--Name of geometry file .vtp, .stl, .obj-->
									<geometry_file>humurus.vtp</geometry_file>
									<!--Color used to display the geometry when visible-->
									<color> 1 1 1</color>
									<!--Name of texture file .jpg, .bmp-->
									<texture_file />
									<!--in body transform specified as 3 rotations (rad) followed by 3 translations rX rY rZ tx ty tz-->
									<transform> -0 0 -0 0 0 0</transform>
									<!--Three scale factors for display purposes: scaleX scaleY scaleZ-->
									<scale_factors> 1 1 1</scale_factors>
									<!--Display Pref. 0:Hide 1:Wire 3:Flat 4:Shaded-->
									<display_preference>4</display_preference>
									<!--Display opacity between 0.0 and 1.0-->
									<opacity>1</opacity>
								</DisplayGeometry>
							</objects>
							<groups />
						</GeometrySet>
						<!--Three scale factors for display purposes: scaleX scaleY scaleZ-->
						<scale_factors> 1 1 1</scale_factors>
						<!--transform relative to owner specified as 3 rotations (rad) followed by 3 translations rX rY rZ tx ty tz-->
						<transform> -0 0 -0 0 0 0</transform>
						<!--Whether to show a coordinate frame-->
						<show_axes>false</show_axes>
						<!--Display Pref. 0:Hide 1:Wire 3:Flat 4:Shaded Can be overriden for individual geometries-->
						<display_preference>4</display_preference>
					</VisibleObject>
					<WrapObjectSet>
						<objects />
						<groups />
					</WrapObjectSet>
				</Body>
				<Body name="ulna">
					<mass>1.1053</mass>
					<mass_center> 0.00971783 -0.0959509 0.024286</mass_center>
					<inertia_xx>0.00541309</inertia_xx>
					<inertia_yy>0.00115318</inertia_yy>
					<inertia_zz>0.00494361</inertia_zz>
					<inertia_xy>0.00031686</inertia_xy>
					<inertia_xz>-7.615e-005</inertia_xz>
					<inertia_yz>0.00109169</inertia_yz>
					<!--Joint that connects this body with the parent body.-->
					<Joint>
						<FreeJoint name="elbow">
							<!--Name of the parent body to which this joint connects its owner body.-->
							<parent_body>humurus</parent_body>
							<!--Location of the joint in the parent body specified in the parent reference frame. Default is (0,0,0).-->
							<location_in_parent>0.0061 -0.2904 -0.0123</location_in_parent>
							<!--Orientation of the joint in the parent body specified in the parent reference frame. Euler XYZ body-fixed rotation angles are used to express the orientation. Default is (0,0,0).-->
							<orientation_in_parent>0 0 0</orientation_in_parent>
							<!--Location of the joint in the child body specified in the child reference frame. For SIMM models, this vector is always the zero vector (i.e., the body reference frame coincides with the joint). -->
							<location>0 0 0</location>
							<!--Orientation of the joint in the owing body specified in the owning body reference frame.  Euler XYZ body-fixed rotation angles are used to express the orientation. -->
							<orientation>0 0 0</orientation>
							<!--Set holding the generalized coordinates (q's) that parmeterize this joint.-->
							<CoordinateSet>
								<objects>
									<Coordinate name="elbow_xRotation">
										<!--Coordinate can describe rotational, translational, or coupled motion. Defaults to rotational.-->
										<motion_type>rotational</motion_type>
										<!--The minimum and maximum values that the coordinate can range between. Rotational coordinate range in radians and Translational in meters.-->
										<range>-1.5707963267949 1.5707963267949</range>
									</Coordinate>
									<Coordinate name="elbow_yRotation">
										<!--Coordinate can describe rotational, translational, or coupled motion. Defaults to rotational.-->
										<motion_type>rotational</motion_type>
										<!--The minimum and maximum values that the coordinate can range between. Rotational coordinate range in radians and Translational in meters.-->
										<range>-1.5707963267949 1.5707963267949</range>
									</Coordinate>
									<Coordinate name="elbow_zRotation">
										<!--Coordinate can describe rotational, translational, or coupled motion. Defaults to rotational.-->
										<motion_type>rotational</motion_type>
										<!--The minimum and maximum values that the coordinate can range between. Rotational coordinate range in radians and Translational in meters.-->
										<range>-1.5707963267949 1.5707963267949</range>
									</Coordinate>
									<Coordinate name="elbow_xTranslation">
										<!--Coordinate can describe rotational, translational, or coupled motion. Defaults to rotational.-->
										<motion_type>translational</motion_type>
										<!--The minimum and maximum values that the coordinate can range between. Rotational coordinate range in radians and Translational in meters.-->
										<range>-1 1</range>
									</Coordinate>
									<Coordinate name="elbow_yTranslation">
										<!--Coordinate can describe rotational, translational, or coupled motion. Defaults to rotational.-->
										<motion_type>translational</motion_type>
										<!--The minimum and maximum values that the coordinate can range between. Rotational coordinate range in radians and Translational in meters.-->
										<range>-1 1</range>
									</Coordinate>
									<Coordinate name="elbow_zTranslation">
										<!--Coordinate can describe rotational, translational, or coupled motion. Defaults to rotational.-->
										<motion_type>translational</motion_type>
										<!--The minimum and maximum values that the coordinate can range between. Rotational coordinate range in radians and Translational in meters.-->
										<range>-1 1</range>
									</Coordinate>
								</objects>
								<groups />
							</CoordinateSet>
							<!--Whether the joint transform defines parent->child or child->parent.-->
							<reverse>false</reverse>
						</FreeJoint>
					</Joint>
					<VisibleObject>
						<!--Set of geometry files and associated attributes, allow .vtp, .stl, .obj-->
						<GeometrySet>
							<objects>
								<DisplayGeometry>
									<!--Name of geometry file .vtp, .stl, .obj-->
									<geometry_file>ulna.vtp</geometry_file>
									<!--Color used to display the geometry when visible-->
									<color> 1 1 1</color>
									<!--Name of texture file .jpg, .bmp-->
									<texture_file />
									<!--in body transform specified as 3 rotations (rad) followed by 3 translations rX rY rZ tx ty tz-->
									<transform> -0 0 -0 0 0 0</transform>
									<!--Three scale factors for display purposes: scaleX scaleY scaleZ-->
									<scale_factors> 1 1 1</scale_factors>
									<!--Display Pref. 0:Hide 1:Wire 3:Flat 4:Shaded-->
									<display_preference>4</display_preference>
									<!--Display opacity between 0.0 and 1.0-->
									<opacity>1</opacity>
								</DisplayGeometry>
							</objects>
							<groups />
						</GeometrySet>
						<!--Three scale factors for display purposes: scaleX scaleY scaleZ-->
						<scale_factors> 1 1 1</scale_factors>
						<!--transform relative to owner specified as 3 rotations (rad) followed by 3 translations rX rY rZ tx ty tz-->
						<transform> -0 0 -0 0 0 0</transform>
						<!--Whether to show a coordinate frame-->
						<show_axes>false</show_axes>
						<!--Display Pref. 0:Hide 1:Wire 3:Flat 4:Shaded Can be overriden for individual geometries-->
						<display_preference>4</display_preference>
					</VisibleObject>
					<WrapObjectSet>
						<objects />
						<groups />
					</WrapObjectSet>
				</Body>
			</objects>
			<groups />
		</BodySet>
		<!--Constraints in the model.-->
		<ConstraintSet>
			<objects />
			<groups />
		</ConstraintSet>
		<!--Forces in the model.-->
		<ForceSet>
			<objects />
			<groups />
		</ForceSet>
		<!--Markers in the model.-->
		<MarkerSet>
			<objects />
			<groups />
		</MarkerSet>
		<!--ContactGeometries  in the model.-->
		<ContactGeometrySet>
			<objects />
			<groups />
		</ContactGeometrySet>
		<!--Controllers in the model.-->
		<ControllerSet name="Controllers">
			<objects />
			<groups />
		</ControllerSet>
		<!--Additional components in the model.-->
		<ComponentSet name="MiscComponents">
			<objects />
			<groups />
		</ComponentSet>
		<!--Probes in the model.-->
		<ProbeSet>
			<objects />
			<groups />
		</ProbeSet>
	</Model>
</OpenSimDocument>

User avatar
Thomas Uchida
Posts: 1790
Joined: Wed May 16, 2012 11:40 am

Re: OpenSim3.3 GUI flashed!

Post by Thomas Uchida » Sun Jul 23, 2017 12:38 pm

The humerus ("humurus" body) is floating, which is not a valid way of defining a model. You need to connect the humerus to something by defining a Joint at line 151 in your model file. If you want the humerus to remain fixed to ground, you can connect it to ground with a WeldJoint (https://simtk.org/api_docs/opensim/api_ ... Joint.html). You may want to look at how other models are constructed (see, e.g., arm26).

POST REPLY