public ChMarker(string name, ChBody body, ChCoordsys rel_pos, ChCoordsys rel_pos_dt, ChCoordsys rel_pos_dtdt) { // SetNameString(name); Body = body; motion_X = new ChFunction_Const(0); // default: no motion motion_Y = new ChFunction_Const(0); motion_Z = new ChFunction_Const(0); motion_ang = new ChFunction_Const(0); motion_axis = ChVector.VECT_Z; rest_coord = new ChCoordsys(new ChVector(0, 0, 0), new ChQuaternion(1, 0, 0, 0));//ChCoordsys.CSYSNORM; motion_type = eChMarkerMotion.M_MOTION_FUNCTIONS; FrameMoving.SetCoord(rel_pos); FrameMoving.SetCoord_dt(rel_pos_dt); FrameMoving.SetCoord_dtdt(rel_pos_dtdt); last_rel_coord = new ChCoordsys(new ChVector(0, 0, 0), new ChQuaternion(1, 0, 0, 0)); //ChCoordsys.CSYSNORM; last_rel_coord_dt = new ChCoordsys(new ChVector(0, 0, 0), new ChQuaternion(0, 0, 0, 0)); // ChCoordsys.CSYSNULL; last_time = 0; UpdateState(); }
/// Someone (ex. an ChExternalObject() ) may send this message to /// the marker to tell that time has changed (even if simulation is /// not running! - so it is different from the usual UpdateTime() -) public void UpdatedExternalTime(double prevtime, double mtime) { double mstep = mtime - prevtime; ChCoordsys m_rel_pos_dt = new ChCoordsys(new ChVector(0, 0, 0), new ChQuaternion(1, 0, 0, 0)); ChCoordsys m_rel_pos_dtdt = new ChCoordsys(new ChVector(0, 0, 0), new ChQuaternion(1, 0, 0, 0)); // do not try to switch on the M_MOTION_KEYFRAMED mode if // we are already in the M_MOTION_EXTERNAL mode, maybe because // a link point-surface is already moving the marker and // it will handle the accelerations by itself if (this.motion_type == eChMarkerMotion.M_MOTION_EXTERNAL) { return; } // otherwise see if a BDF is needed, cause an external 3rd party is moving the marker this.motion_type = eChMarkerMotion.M_MOTION_FUNCTIONS; // if POSITION or ROTATION ("rel_pos") has been changed in acceptable time step... if ((!(ChVector.Vequal(FrameMoving.coord.pos, last_rel_coord.pos)) || !(ChQuaternion.Qequal(FrameMoving.coord.rot, last_rel_coord.rot))) && (Math.Abs(mstep) < 0.1) && (mstep != 0)) { // ... and if motion wasn't caused by motion laws, then it was a keyframed movement! if ((motion_X.Get_y(mtime) == 0) && (motion_Y.Get_y(mtime) == 0) && (motion_Z.Get_y(mtime) == 0) && (motion_ang.Get_y(mtime) == 0) && (motion_X.Get_Type() == ChFunction.FunctionType.FUNCT_CONST) && (motion_Y.Get_Type() == ChFunction.FunctionType.FUNCT_CONST) && (motion_Z.Get_Type() == ChFunction.FunctionType.FUNCT_CONST) && (motion_ang.Get_Type() == ChFunction.FunctionType.FUNCT_CONST)) { // compute the relative speed by BDF ! m_rel_pos_dt.pos = ChVector.Vmul(ChVector.Vsub(FrameMoving.coord.pos, last_rel_coord.pos), 1 / mstep); m_rel_pos_dt.rot = ChQuaternion.Qscale(ChQuaternion.Qsub(FrameMoving.coord.rot, last_rel_coord.rot), 1 / mstep); // compute the relative acceleration by BDF ! m_rel_pos_dtdt.pos = ChVector.Vmul(ChVector.Vsub(m_rel_pos_dt.pos, last_rel_coord_dt.pos), 1 / mstep); m_rel_pos_dtdt.rot = ChQuaternion.Qscale(ChQuaternion.Qsub(m_rel_pos_dt.rot, last_rel_coord_dt.rot), 1 / mstep); // Set the position, speed and acceleration in relative space, // automatically getting also the absolute values, FrameMoving.SetCoord_dt(m_rel_pos_dt); FrameMoving.SetCoord_dtdt(m_rel_pos_dtdt); // update the remaining state variables this.UpdateState(); // remember that the movement of this guy won't need further update // of speed and acc. via motion laws! this.motion_type = eChMarkerMotion.M_MOTION_KEYFRAMED; } } // restore state buffers and that's all. last_time = ChTime; last_rel_coord = (ChCoordsys)FrameMoving.coord; last_rel_coord_dt = (ChCoordsys)FrameMoving.coord_dt; }
private ChFrameMoving <double> abs_frame = new ChFrameMoving <double>(); //< absolute frame position /* public void Start() * { * FrameMoving = new ChFrameMoving<double>(); * Body = null; * rest_coord = new ChCoordsys(new ChVector(0, 0, 0), new ChQuaternion(1, 0, 0, 0));//ChCoordsys.CSYSNORM; * motion_type = eChMarkerMotion.M_MOTION_FUNCTIONS; * motion_axis = ChVector.VECT_Z; * last_rel_coord = new ChCoordsys(new ChVector(0, 0, 0), new ChQuaternion(1, 0, 0, 0));//ChCoordsys.CSYSNORM; * last_rel_coord_dt = new ChCoordsys(new ChVector(0, 0, 0), new ChQuaternion(0, 0, 0, 0));// ChCoordsys.CSYSNULL; * last_time = 0; * motion_X = new ChFunction_Const(0); // default: no motion * motion_Y = new ChFunction_Const(0); * motion_Z = new ChFunction_Const(0); * motion_ang = new ChFunction_Const(0); * * UpdateState(); * }*/ public ChMarker() { FrameMoving = new ChFrameMoving <double>(); Body = null; rest_coord = new ChCoordsys(new ChVector(0, 0, 0), new ChQuaternion(1, 0, 0, 0));//ChCoordsys.CSYSNORM; motion_type = eChMarkerMotion.M_MOTION_FUNCTIONS; motion_axis = ChVector.VECT_Z; last_rel_coord = new ChCoordsys(new ChVector(0, 0, 0), new ChQuaternion(1, 0, 0, 0)); //ChCoordsys.CSYSNORM; last_rel_coord_dt = new ChCoordsys(new ChVector(0, 0, 0), new ChQuaternion(0, 0, 0, 0)); // ChCoordsys.CSYSNULL; last_time = 0; motion_X = new ChFunction_Const(0); // default: no motion motion_Y = new ChFunction_Const(0); motion_Z = new ChFunction_Const(0); motion_ang = new ChFunction_Const(0); UpdateState(); }
public ChMarker(ChMarker other) : base(other) { FrameMoving = new ChFrameMoving <double>(other.FrameMoving); Body = null; motion_X = new ChFunction(other.motion_X.Clone()); motion_Y = new ChFunction(other.motion_Y.Clone()); motion_Z = new ChFunction(other.motion_Z.Clone()); motion_ang = new ChFunction(other.motion_ang.Clone()); motion_axis = other.motion_axis; rest_coord = other.rest_coord; motion_type = other.motion_type; abs_frame = other.abs_frame; last_rel_coord = other.last_rel_coord; last_rel_coord_dt = other.last_rel_coord_dt; last_time = other.last_time; }
/// Sets the way the motion of this marker (if any) is handled (see /// the eChMarkerMotion enum options). public void SetMotionType(eChMarkerMotion m_motion) { motion_type = m_motion; }