- 积分
- 0
- 注册时间
- 2014-8-13
- 仿真币
-
- 最后登录
- 1970-1-1
|
本帖最后由 xifengyang 于 2015-5-18 22:18 编辑
最近在编写子程序,尝试把 《机械系统动力学分析及ADAMS应用教程》中的例子做了一下。仿真时发现小球不是沿着斜面运动而是做匀速线下的直线的运动(很缓慢)。希望能与大家交流交流,多多指教~~希望把这个例子真正做通,给大家一个参照。
一下是程序
#include "slv_c_utils.h"
/*
* Using a function typedef from slv_c_utils.h, please declare your
* user subroutine before defining it. This will allow a compiler to
* perform type checking for your subroutine arguments.
*/
adams_c_Gfosub Gfosub;
/*
* Define a subroutine named 'Gfosub'. Any name is allowed,
* as long as it is mixed case and the name is specified in
* the ADAMS input file using the ROUTINE= keyword.
*
* Adams distinguishes between FORTRAN and C subroutines by looking
* up the function name in the library. If it finds a mixed case
* name then it assumes that the function is a C function. Otherwise
* it assumes Fortran.
*/
void Gfosub(const struct sAdamsGforce* gfo, double time, int dflag, int iflag, double* result)
{
double ct = gfo->PAR[0];
double cr = gfo->PAR[1];
int im = (int)gfo->PAR[2];
int jm = (int)gfo->PAR[3];
double vel[6];
int ipar[3];
int nstates;
int errflg;
/*
Call SYSARY to collect information for the
calculations below. Note: if IFLAG is true, this
call is actually setting functional dependencies.
--- Use VEL to get marker translational and rotational
velocities
*/
ipar[0] = im;
ipar[1] = jm;
ipar[2] = jm;
c_sysary("VEL", ipar, 3, vel, &nstates, &errflg);
/*
--- Check SYSARY call through ERRMES utility routine
*/
c_errmes(errflg,"Error calling SYSARY for VEL", gfo->ID, "STOP");
/*
--- Evaluate GFORCE components -------------------------
*/
result[0] = -ct*vel[0];
result[1] = -ct*vel[1];
result[2] = -ct*vel[2];
result[3] = -cr*vel[3];
result[4] = -cr*vel[4];
result[5] = -cr*vel[5];
}
|
|