Commit 0cf323f2 authored by Olivier Lantsoght's avatar Olivier Lantsoght
Browse files

[MBsysPy][Tuto] Update "User constraints"

parent e2d924bf
# -*- coding: utf-8 -*-
"""Module for the definition of functions related to Equilibrium analysis."""
# Author: Robotran Team
# (c) Universite catholique de Louvain, 2020
def user_dirdyn_init(mbs_data, mbs_dirdyn):
"""Run specific operation required by the user before running direct dynamic.
Parameters
----------
mbs_data : MBsysPy.MbsData
The instance containing the multibody project.
mbs_dirdyn : MBsysPy.MbsDirdyn
The instance of the current direct dynamic process.
Returns
-------
None.
"""
return
def user_dirdyn_loop(mbs_data, mbs_dirdyn):
"""Run specific operation required by the user at the end of each integrator step.
In case of multistep integrator, this function is not called at intermediate
steps.
Parameters
----------
mbs_data : MBsysPy.MbsData
The instance containing the multibody project.
mbs_dirdyn : MBsysPy.MbsDirdyn
The instance of the current direct dynamic process.
Returns
-------
None.
"""
return
def user_dirdyn_finish(mbs_data, mbs_dirdyn):
"""Run specific operations required by the user when direct dynamic analysis ends.
Parameters
----------
mbs_data : MBsysPy.MbsData
The instance containing the multibody project.
mbs_dirdyn : MBsysPy.MbsDirdyn
The instance of the current direct dynamic process.
Returns
-------
None.
"""
return
# coding _*_ utf-8 _*
"""Robotran tutorial project in Python, ""User constraints" part."""
# author: Robotran Team
# Copyright 2019 Universite Catholique de Louvain
"""
author: Thomas Gillis
Created on 1/7/2013
Last update on 25/11/2019
Copyright 2019 Universite Catholique de Louvain
"""
#==============================================================================
# =============================================================================
# Packages loading
#==============================================================================
import sys, time
sys.path.insert(1,"./../../../..") # Relative path for this example script
# =============================================================================
import sys
import time
# Add the relative default build of MBsysC folder (Linux/MacOs).
sys.path.insert(1, "./../../../../../build/python")
import MBsysPy as robotran
#==============================================================================
# =============================================================================
# Project loading
#==============================================================================
# =============================================================================
print("\n>>PYTHON>> Loading Project!")
mbs_data = robotran.MbsData("../dataR/Userconstraints.mbs",
mbs_data = robotran.MbsData("../dataR/Userconstraints.mbs",
prj_functions_c=None, prj_lib_path="..")
#==============================================================================
# =============================================================================
# Setting user constraint
#==============================================================================
# =============================================================================
nUsrConst = 1
mbs_data.set_nb_userc(nUsrConst)
print(mbs_data)
#==============================================================================
# =============================================================================
# Coordinate partitioning
#==============================================================================
# =============================================================================
print("\n>>PYTHON>> Running partitioning!")
mbs_part = robotran.MbsPart(mbs_data)
mbs_part.set_options(rowperm = 1)
mbs_part.set_options(rowperm=1)
mbs_part.run()
#==============================================================================
# =============================================================================
# Computation
#==============================================================================
# =============================================================================
print("\n>>PYTHON>> Running direct dynamic!")
mbs_dirdyn = robotran.MbsDirdyn(mbs_data)
t0 = time.time()
results = mbs_dirdyn.run()
t1 = time.time()
print("Computation time in second: "+ str(t1-t0))
print("Computation time in second: {:.1f}".format(t1 - t0))
##==============================================================================
## Plotting
##==============================================================================
# =============================================================================
# Plotting
# =============================================================================
from matplotlib import pyplot as plt
q = results.q
plt.figure(mbs_data.mbs_name+str(" Q1"))
plt.plot(q[:,0], q[:,1])
plt.figure(mbs_data.mbs_name + str(" Q1"))
plt.plot(q[:, 0], q[:, 1])
plt.xlabel("time [s]")
plt.ylabel("q1 [rad]")
plt.xlim((0,5))
plt.ylim((-0.1,0.25))
plt.xlim((0, 5))
plt.ylim((-0.1, 0.25))
plt.figure(mbs_data.mbs_name+str(" Q2"))
plt.plot(q[:,0], q[:,2])
plt.figure(mbs_data.mbs_name + str(" Q2"))
plt.plot(q[:, 0], q[:, 2])
plt.xlabel("time [s]")
plt.ylabel("q2 [m]")
plt.xlim((0,5))
plt.ylim((0.2,0.4))
plt.xlim((0, 5))
plt.ylim((0.2, 0.4))
plt.show()
\ No newline at end of file
plt.show()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment