public Brake(agx.Hinge hinge, double[] brakeForceRange) { // Initialize the brakes on the hinges m_hinge = hinge; m_hinge.getLock1D().setEnable(false); m_hinge.getLock1D().setForceRange(new agx.RangeReal(brakeForceRange[0], brakeForceRange[1])); m_hinge.getLock1D().setCompliance(1E-12); update(); }
/// <summary> /// Initialize the whole vehicle /// </summary> private void initializeVehicle() { if (m_initialized) { return; } var sim = GetSimulation(); Assert.IsNotNull(sim); // Access the hinge used for steering m_steeringHinge = GetSimulation().getHinge("WaistHingeTurning"); Assert.IsNotNull(m_steeringHinge); m_steeringHinge.getMotor1D().setEnable(true); m_steeringHinge.getMotor1D().setSpeed(0.0f); m_steeringHinge.getMotor1D().setLockedAtZeroSpeed(true); /// Access all the hinges attached to all the rims var hingeJointNames = new List <string> { "RightRearHinge", "LeftRearHinge", "RightFrontHinge", "LeftFrontHinge" }; foreach (var n in hingeJointNames) { var hinge = sim.getHinge(n); Assert.IsNotNull(hinge, string.Format("Hinge {0} is missing in Simulation", n)); m_wheelHinges.Add(hinge.getName(), hinge); } if (m_chassieRigidBody == null) { m_chassieRigidBody = sim.getRigidBody("FrontBody"); Assert.IsNotNull(m_chassieRigidBody); } //Hinge.GetController<TargetSpeedController>().Enable = true; // Make sure body exists before I start using it. //Body.GetInitialized<RigidBody>().Native.setEnable(false); initializeTires(); // Create the Vehicle class that initializes brakes etc. m_vehicle = new Vehicle(GetSimulation(), m_wheelHinges); m_initialized = true; }
protected override bool Initialize() { if (!agx.Runtime.instance().isModuleEnabled("AgX-DriveTrain")) { Debug.LogWarning("WheelLoader requires a valid license for the AGX Dynamics module: AgX-DriveTrain", this); } PowerLine = new agxPowerLine.PowerLine(); PowerLine.setName(name); Engine = new agxDriveTrain.CombustionEngine(InletVolume); TorqueConverter = new agxDriveTrain.TorqueConverter(); GearBox = new agxDriveTrain.GearBox(); Differentials[(int)DifferentialLocation.Rear] = new agxDriveTrain.Differential(); Differentials[(int)DifferentialLocation.Center] = new agxDriveTrain.Differential(); Differentials[(int)DifferentialLocation.Front] = new agxDriveTrain.Differential(); m_actuators[(int)WheelLocation.LeftFront] = new agxPowerLine.RotationalActuator(LeftFrontHinge.GetInitialized <Constraint>().Native.asHinge()); m_actuators[(int)WheelLocation.RightFront] = new agxPowerLine.RotationalActuator(RightFrontHinge.GetInitialized <Constraint>().Native.asHinge()); m_actuators[(int)WheelLocation.LeftRear] = new agxPowerLine.RotationalActuator(LeftRearHinge.GetInitialized <Constraint>().Native.asHinge()); m_actuators[(int)WheelLocation.RightRear] = new agxPowerLine.RotationalActuator(RightRearHinge.GetInitialized <Constraint>().Native.asHinge()); foreach (var wheelHinge in WheelHinges) { wheelHinge.GetController <TargetSpeedController>().Enable = false; } var engineTorqueConverterShaft = new agxDriveTrain.Shaft(); var torqueConverterGearBoxShaft = new agxDriveTrain.Shaft(); var gearBoxCenterDiffShaft = new agxDriveTrain.Shaft(); var centerDiffRearDiffShaft = new agxDriveTrain.Shaft(); var centerDiffFrontDiffShaft = new agxDriveTrain.Shaft(); var frontDiffFrontLeftWheelShaft = new agxDriveTrain.Shaft(); var frontDiffFrontRightWheelShaft = new agxDriveTrain.Shaft(); var rearDiffRearLeftWheelShaft = new agxDriveTrain.Shaft(); var rearDiffRearRightWheelShaft = new agxDriveTrain.Shaft(); PowerLine.setSource(Engine); Engine.connect(engineTorqueConverterShaft); engineTorqueConverterShaft.connect(TorqueConverter); TorqueConverter.connect(torqueConverterGearBoxShaft); torqueConverterGearBoxShaft.connect(GearBox); GearBox.connect(gearBoxCenterDiffShaft); gearBoxCenterDiffShaft.connect(Differentials[(int)DifferentialLocation.Center]); Differentials[(int)DifferentialLocation.Center].connect(centerDiffFrontDiffShaft); centerDiffFrontDiffShaft.connect(Differentials[(int)DifferentialLocation.Front]); Differentials[(int)DifferentialLocation.Front].connect(frontDiffFrontLeftWheelShaft); Differentials[(int)DifferentialLocation.Front].connect(frontDiffFrontRightWheelShaft); frontDiffFrontLeftWheelShaft.connect(m_actuators[(int)WheelLocation.LeftFront]); frontDiffFrontRightWheelShaft.connect(m_actuators[(int)WheelLocation.RightFront]); Differentials[(int)DifferentialLocation.Center].connect(centerDiffRearDiffShaft); centerDiffRearDiffShaft.connect(Differentials[(int)DifferentialLocation.Rear]); Differentials[(int)DifferentialLocation.Rear].connect(rearDiffRearLeftWheelShaft); Differentials[(int)DifferentialLocation.Rear].connect(rearDiffRearRightWheelShaft); rearDiffRearLeftWheelShaft.connect(m_actuators[(int)WheelLocation.LeftRear]); rearDiffRearRightWheelShaft.connect(m_actuators[(int)WheelLocation.RightRear]); var munu = new agx.RealPairVector(new agx.RealPair[] { new agx.RealPair(-0.0001, 0.00), new agx.RealPair(0.00001, 0.50), new agx.RealPair(0.00011, 2.00), new agx.RealPair(0.00100, 2.00), new agx.RealPair(0.20000, 1.10), new agx.RealPair(0.40000, 1.15), new agx.RealPair(0.60000, 1.05), new agx.RealPair(0.80000, 1.01), new agx.RealPair(0.90000, 0.99), new agx.RealPair(1.00000, 0.98), new agx.RealPair(1.00100, 0.98) }); TorqueConverter.setMuTable(munu); TorqueConverter.setMaxMultiplication(2.0); TorqueConverter.setPumpTorqueReferenceRPM(1000.0); GearBox.setGearRatios(new agx.RealVector(new double[] { GearRatios.x, GearRatios.y })); GearBox.gearUp(); GetSimulation().add(PowerLine); var f1 = new agx.Frame(); var f2 = new agx.Frame(); agx.Constraint.calculateFramesFromBody(new agx.Vec3(), agx.Vec3.X_AXIS(), gearBoxCenterDiffShaft.getRotationalDimension().getOrReserveBody(), f1, null, f2); BrakeHinge = new agx.Hinge(gearBoxCenterDiffShaft.getRotationalDimension().getOrReserveBody(), f1, null, f2); GetSimulation().add(BrakeHinge); try { GetOrCreateTireModelProperties(); foreach (WheelLocation location in Enum.GetValues(typeof(WheelLocation))) { GetOrCreateTireModel(location)?.GetInitialized <TwoBodyTire>(); } } catch (Exception e) { Debug.LogWarning("Unable to initialize tire models: " + e.Message); } return(true); }
protected override bool Initialize() { RemoveInvalidRollers(); var tracks = FindTracks(); if (tracks.Length == 0) { Debug.LogWarning("Belt: No tracks found.", this); return(false); } if (tracks.Any(track => track.GetInitialized <Track>() == null) || // Tracks has zero nodes when the license isn't loaded or // doesn't include the tracks module. tracks.Any(Track => Track.Native.getNumNodes() == 0)) { Debug.LogError("Belt: One or more tracks failed to initialize.", this); return(false); } m_tracks = tracks; if (m_tracks.Length > 1) { ulong numNodes = m_tracks.First().Native.getNumNodes(); ulong stride = System.Math.Min(System.Math.Max((ulong)ConnectingConstraintStride, 1), numNodes); while (stride > 1 && (numNodes % stride) != 0) { --stride; } if ((int)stride != ConnectingConstraintStride) { Debug.Log($"Belt: Connecting constraint stride changed from {ConnectingConstraintStride} to {stride} " + $"to match node count: {m_tracks.First().Native.getNumNodes()}.", this); } for (int i = 0; i < m_tracks.Length; ++i) { m_tracks[i].Native.addGroup(GetGroupName(i)); } ConnectingConstraints = new agx.Constraint[m_tracks.Length - 1, (int)(numNodes / stride)]; for (int i = 1; i < m_tracks.Length; ++i) { var prev = m_tracks[i - 1]; var curr = m_tracks[i]; GetSimulation().getSpace().setEnablePair(GetGroupName(i - 1), GetGroupName(i), false); var connectingConstraintIndex = 0; for (ulong nodeIndex = 0; nodeIndex < prev.Native.getNumNodes(); ++nodeIndex) { if ((nodeIndex % stride) != 0) { continue; } var prevTrackNode = prev.Native.getNode(nodeIndex); var currTrackNode = curr.Native.getNode(nodeIndex); var constraintCenter = 0.5 * (prevTrackNode.getCenterPosition() + currTrackNode.getCenterPosition()); var constraintAxis = prevTrackNode.getDirection().normal(); var otherAxis = (constraintCenter - prevTrackNode.getCenterPosition()).normal(); // Constraint frame we're about to create: // x or TRANSLATIONAL_1: Along otherAxis, i.e., separation of the two nodes. // y or TRANSLATIONAL_2: Up/down between the two nodes. // z or TRANSLATIONAL_3: Along the track. var prevTrackNodeFrame = new agx.Frame(); var currTrackNodeFrame = new agx.Frame(); agx.Constraint.calculateFramesFromWorld(constraintCenter, constraintAxis, otherAxis, prevTrackNode.getRigidBody(), prevTrackNodeFrame, currTrackNode.getRigidBody(), currTrackNodeFrame); ConnectingConstraints[i - 1, connectingConstraintIndex++] = new agx.Hinge(prevTrackNode.getRigidBody(), prevTrackNodeFrame, currTrackNode.getRigidBody(), currTrackNodeFrame); } } foreach (var constraint in ConnectingConstraints) { if (constraint == null) { Debug.LogWarning("Unexpected null connecting constraint.", this); continue; } constraint.setName("connecting"); // Properties will be applied during BeltProperties.Register // when all properties are synchronized for this belt after // Initialize is done. GetSimulation().add(constraint); } } return(true); }