浏览代码

Experiment with joint drive in Crawler.

/PhysXArticulations20201
Vilmantas Balasevicius 5 年前
当前提交
dfc08082
共有 12 个文件被更改,包括 3847 次插入22 次删除
  1. 21
      UnitySDK/Assets/ML-Agents/Examples/Crawler/Scripts/ArticulatedCrawlerAgent.cs
  2. 30
      UnitySDK/Assets/ML-Agents/Examples/Crawler/Scripts/ArticulatedJointDriveController.cs
  3. 1001
      UnitySDK/Assets/ML-Agents/Examples/Crawler/Prefabs/ArticulatedCrawler.prefab
  4. 7
      UnitySDK/Assets/ML-Agents/Examples/Crawler/Prefabs/ArticulatedCrawler.prefab.meta
  5. 1001
      UnitySDK/Assets/ML-Agents/Examples/Crawler/Prefabs/ArticulatedFixedPlatform.prefab
  6. 7
      UnitySDK/Assets/ML-Agents/Examples/Crawler/Prefabs/ArticulatedFixedPlatform.prefab.meta
  7. 617
      UnitySDK/Assets/ML-Agents/Examples/Crawler/Scenes/ArticulatedCrawlerManualControl.unity
  8. 7
      UnitySDK/Assets/ML-Agents/Examples/Crawler/Scenes/ArticulatedCrawlerManualControl.unity.meta
  9. 1001
      UnitySDK/Assets/ML-Agents/Examples/Crawler/Scenes/ArticulatedCrawlerStaticTarget.unity
  10. 7
      UnitySDK/Assets/ML-Agents/Examples/Crawler/Scenes/ArticulatedCrawlerStaticTarget.unity.meta
  11. 167
      UnitySDK/Assets/ML-Agents/Examples/Crawler/Scripts/ArticulatedCrawlerManualControl.cs
  12. 3
      UnitySDK/Assets/ML-Agents/Examples/Crawler/Scripts/ArticulatedCrawlerManualControl.cs.meta

21
UnitySDK/Assets/ML-Agents/Examples/Crawler/Scripts/ArticulatedCrawlerAgent.cs


public Transform leg3Upper;
public Transform leg3Lower;
[Header("Joint Settings")][Space(10)] JointDriveController m_JdController;
[Header("Joint Settings")][Space(10)] ArticulatedJointDriveController m_JdController;
Vector3 m_DirToTarget;
float m_MovingTowardsDot;
float m_FacingDot;

public override void InitializeAgent()
{
m_JdController = GetComponent<JointDriveController>();
m_JdController = GetComponent<ArticulatedJointDriveController>();
m_CurrentDecisionStep = 1;
m_DirToTarget = target.position - body.position;

/// <summary>
/// Add relevant information on each body part to observations.
/// </summary>
public void CollectObservationBodyPart(BodyPart bp)
public void CollectObservationBodyPart(ArticulationBodyPart bp)
var rb = bp.rb;
var arb = bp.arb;
var velocityRelativeToLookRotationToTarget = m_TargetDirMatrix.inverse.MultiplyVector(rb.velocity);
var velocityRelativeToLookRotationToTarget = m_TargetDirMatrix.inverse.MultiplyVector(arb.velocity);
var angularVelocityRelativeToLookRotationToTarget = m_TargetDirMatrix.inverse.MultiplyVector(rb.angularVelocity);
var angularVelocityRelativeToLookRotationToTarget = m_TargetDirMatrix.inverse.MultiplyVector(arb.angularVelocity);
if (bp.rb.transform != body)
if (bp.arb.transform != body)
var localPosRelToBody = body.InverseTransformPoint(rb.position);
AddVectorObs(localPosRelToBody);
// Will need to rewrite this because body parts are in hiearchy, not flat like in RigidBody case
//var localPosRelToBody = body.InverseTransformPoint(arb.position);
//AddVectorObs(localPosRelToBody);
AddVectorObs(bp.currentXNormalizedRot); // Current x rot
AddVectorObs(bp.currentYNormalizedRot); // Current y rot
AddVectorObs(bp.currentZNormalizedRot); // Current z rot

/// </summary>
void RewardFunctionMovingTowards()
{
m_MovingTowardsDot = Vector3.Dot(m_JdController.bodyPartsDict[body].rb.velocity, m_DirToTarget.normalized);
m_MovingTowardsDot = Vector3.Dot(m_JdController.bodyPartsDict[body].arb.velocity, m_DirToTarget.normalized);
AddReward(0.03f * m_MovingTowardsDot);
}

30
UnitySDK/Assets/ML-Agents/Examples/Crawler/Scripts/ArticulatedJointDriveController.cs


{
bp.arb.transform.position = bp.startingPos;
bp.arb.transform.rotation = bp.startingRot;
bp.arb.velocity = Vector3.zero;
bp.arb.angularVelocity = Vector3.zero;
// Can't assigned articulation body velocitys/angularVelocities
//bp.arb.velocity = Vector3.zero;
//bp.arb.angularVelocity = Vector3.zero;
if (bp.groundContact)
{
bp.groundContact.touchingGround = false;

public void SetJointStrength(float strength)
{
ArticulationDrive drive = arb.xDrive;
var xDrive = arb.xDrive;
var yDrive = arb.yDrive;
var zDrive = arb.zDrive;
drive.stiffness = thisJdController.maxJointSpring;
drive.damping = thisJdController.jointDampen;
drive.forceLimit = rawVal;
xDrive.stiffness = yDrive.stiffness = zDrive.stiffness = thisJdController.maxJointSpring;
xDrive.damping = yDrive.damping = zDrive.damping = thisJdController.jointDampen;
xDrive.forceLimit = yDrive.forceLimit = zDrive.forceLimit = rawVal;
arb.xDrive = drive;
arb.yDrive = drive;
arb.zDrive = drive;
arb.xDrive = xDrive;
arb.yDrive = yDrive;
arb.zDrive = zDrive;
//joint.slerpDrive = jd;
currentStrength = rawVal;
}

public void GetCurrentJointForces()
{
/*
bodyPart.currentJointForce = bodyPart.arb;
// Why do we need a force here ?
//bodyPart.currentJointForce = bodyPart.arb;
bodyPart.currentJointForceSqrMag = bodyPart.joint.currentForce.magnitude;
bodyPart.currentJointTorque = bodyPart.joint.currentTorque;
bodyPart.currentJointTorqueSqrMag = bodyPart.joint.currentTorque.magnitude;

}
}
}
*/
}
}
}

1001
UnitySDK/Assets/ML-Agents/Examples/Crawler/Prefabs/ArticulatedCrawler.prefab
文件差异内容过多而无法显示
查看文件

7
UnitySDK/Assets/ML-Agents/Examples/Crawler/Prefabs/ArticulatedCrawler.prefab.meta


fileFormatVersion: 2
guid: 1661ce2a8a3cdfd3480c3d24bddd72f2
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

1001
UnitySDK/Assets/ML-Agents/Examples/Crawler/Prefabs/ArticulatedFixedPlatform.prefab
文件差异内容过多而无法显示
查看文件

7
UnitySDK/Assets/ML-Agents/Examples/Crawler/Prefabs/ArticulatedFixedPlatform.prefab.meta


fileFormatVersion: 2
guid: 0647effc95026f46dbf821c2032caba7
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

617
UnitySDK/Assets/ML-Agents/Examples/Crawler/Scenes/ArticulatedCrawlerManualControl.unity


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!29 &1
OcclusionCullingSettings:
m_ObjectHideFlags: 0
serializedVersion: 2
m_OcclusionBakeSettings:
smallestOccluder: 5
smallestHole: 0.25
backfaceThreshold: 100
m_SceneGUID: 00000000000000000000000000000000
m_OcclusionCullingData: {fileID: 0}
--- !u!104 &2
RenderSettings:
m_ObjectHideFlags: 0
serializedVersion: 9
m_Fog: 0
m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
m_FogMode: 3
m_FogDensity: 0.01
m_LinearFogStart: 0
m_LinearFogEnd: 300
m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1}
m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1}
m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1}
m_AmbientIntensity: 1
m_AmbientMode: 0
m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1}
m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0}
m_HaloStrength: 0.5
m_FlareStrength: 1
m_FlareFadeSpeed: 3
m_HaloTexture: {fileID: 0}
m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0}
m_DefaultReflectionMode: 0
m_DefaultReflectionResolution: 128
m_ReflectionBounces: 1
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
m_ObjectHideFlags: 0
serializedVersion: 11
m_GIWorkflowMode: 1
m_GISettings:
serializedVersion: 2
m_BounceScale: 1
m_IndirectOutputScale: 1
m_AlbedoBoost: 1
m_EnvironmentLightingMode: 0
m_EnableBakedLightmaps: 1
m_EnableRealtimeLightmaps: 0
m_LightmapEditorSettings:
serializedVersion: 12
m_Resolution: 2
m_BakeResolution: 40
m_AtlasSize: 1024
m_AO: 0
m_AOMaxDistance: 1
m_CompAOExponent: 1
m_CompAOExponentDirect: 0
m_ExtractAmbientOcclusion: 0
m_Padding: 2
m_LightmapParameters: {fileID: 0}
m_LightmapsBakeMode: 1
m_TextureCompression: 1
m_FinalGather: 0
m_FinalGatherFiltering: 1
m_FinalGatherRayCount: 256
m_ReflectionCompression: 2
m_MixedBakeMode: 2
m_BakeBackend: 1
m_PVRSampling: 1
m_PVRDirectSampleCount: 32
m_PVRSampleCount: 512
m_PVRBounces: 2
m_PVREnvironmentSampleCount: 256
m_PVREnvironmentReferencePointCount: 2048
m_PVRFilteringMode: 1
m_PVRDenoiserTypeDirect: 1
m_PVRDenoiserTypeIndirect: 1
m_PVRDenoiserTypeAO: 1
m_PVRFilterTypeDirect: 0
m_PVRFilterTypeIndirect: 0
m_PVRFilterTypeAO: 0
m_PVREnvironmentMIS: 1
m_PVRCulling: 1
m_PVRFilteringGaussRadiusDirect: 1
m_PVRFilteringGaussRadiusIndirect: 5
m_PVRFilteringGaussRadiusAO: 2
m_PVRFilteringAtrousPositionSigmaDirect: 0.5
m_PVRFilteringAtrousPositionSigmaIndirect: 2
m_PVRFilteringAtrousPositionSigmaAO: 1
m_ExportTrainingData: 0
m_TrainingDataDestination: TrainingData
m_LightProbeSampleCountMultiplier: 4
m_LightingDataAsset: {fileID: 0}
m_UseShadowmask: 1
--- !u!196 &4
NavMeshSettings:
serializedVersion: 2
m_ObjectHideFlags: 0
m_BuildSettings:
serializedVersion: 2
agentTypeID: 0
agentRadius: 0.5
agentHeight: 2
agentSlope: 45
agentClimb: 0.4
ledgeDropHeight: 0
maxJumpAcrossDistance: 0
minRegionArea: 2
manualCellSize: 0
cellSize: 0.16666667
manualTileSize: 0
tileSize: 256
accuratePlacement: 0
debug:
m_Flags: 0
m_NavMeshData: {fileID: 0}
--- !u!1 &1167278637 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 1608323988796809829, guid: 1661ce2a8a3cdfd3480c3d24bddd72f2,
type: 3}
m_PrefabInstance: {fileID: 1445410834}
m_PrefabAsset: {fileID: 0}
--- !u!1 &1193539137
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1193539139}
- component: {fileID: 1193539138}
m_Layer: 0
m_Name: Directional Light
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!108 &1193539138
Light:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1193539137}
m_Enabled: 1
serializedVersion: 10
m_Type: 1
m_Shape: 0
m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1}
m_Intensity: 1
m_Range: 10
m_SpotAngle: 30
m_InnerSpotAngle: 21.80208
m_CookieSize: 10
m_Shadows:
m_Type: 2
m_Resolution: -1
m_CustomResolution: -1
m_Strength: 1
m_Bias: 0.05
m_NormalBias: 0.4
m_NearPlane: 0.2
m_CullingMatrixOverride:
e00: 1
e01: 0
e02: 0
e03: 0
e10: 0
e11: 1
e12: 0
e13: 0
e20: 0
e21: 0
e22: 1
e23: 0
e30: 0
e31: 0
e32: 0
e33: 1
m_UseCullingMatrixOverride: 0
m_Cookie: {fileID: 0}
m_DrawHalo: 0
m_Flare: {fileID: 0}
m_RenderMode: 0
m_CullingMask:
serializedVersion: 2
m_Bits: 4294967295
m_RenderingLayerMask: 1
m_Lightmapping: 4
m_LightShadowCasterMode: 0
m_AreaSize: {x: 1, y: 1}
m_BounceIntensity: 1
m_ColorTemperature: 6570
m_UseColorTemperature: 0
m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0}
m_UseBoundingSphereOverride: 0
m_ShadowRadius: 0
m_ShadowAngle: 0
--- !u!4 &1193539139
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1193539137}
m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261}
m_LocalPosition: {x: 0, y: 3, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0}
--- !u!1 &1304015942
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1304015945}
- component: {fileID: 1304015944}
- component: {fileID: 1304015943}
m_Layer: 0
m_Name: Main Camera
m_TagString: MainCamera
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!81 &1304015943
AudioListener:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1304015942}
m_Enabled: 1
--- !u!20 &1304015944
Camera:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1304015942}
m_Enabled: 1
serializedVersion: 2
m_ClearFlags: 1
m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0}
m_projectionMatrixMode: 1
m_GateFitMode: 2
m_FOVAxisMode: 0
m_SensorSize: {x: 36, y: 24}
m_LensShift: {x: 0, y: 0}
m_FocalLength: 50
m_NormalizedViewPortRect:
serializedVersion: 2
x: 0
y: 0
width: 1
height: 1
near clip plane: 0.3
far clip plane: 1000
field of view: 60
orthographic: 0
orthographic size: 5
m_Depth: -1
m_CullingMask:
serializedVersion: 2
m_Bits: 4294967295
m_RenderingPath: -1
m_TargetTexture: {fileID: 0}
m_TargetDisplay: 0
m_TargetEye: 3
m_HDR: 1
m_AllowMSAA: 1
m_AllowDynamicResolution: 0
m_ForceIntoRT: 0
m_OcclusionCulling: 1
m_StereoConvergence: 10
m_StereoSeparation: 0.022
--- !u!4 &1304015945
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1304015942}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 1, z: -10}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1001 &1445410834
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 1129387478859796, guid: 1661ce2a8a3cdfd3480c3d24bddd72f2, type: 3}
propertyPath: m_Name
value: ArticulatedCrawler
objectReference: {fileID: 0}
- target: {fileID: 4283901937423508, guid: 1661ce2a8a3cdfd3480c3d24bddd72f2, type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4283901937423508, guid: 1661ce2a8a3cdfd3480c3d24bddd72f2, type: 3}
propertyPath: m_LocalPosition.y
value: 2.1
objectReference: {fileID: 0}
- target: {fileID: 4283901937423508, guid: 1661ce2a8a3cdfd3480c3d24bddd72f2, type: 3}
propertyPath: m_LocalPosition.z
value: 6.3
objectReference: {fileID: 0}
- target: {fileID: 4283901937423508, guid: 1661ce2a8a3cdfd3480c3d24bddd72f2, type: 3}
propertyPath: m_LocalRotation.x
value: -0
objectReference: {fileID: 0}
- target: {fileID: 4283901937423508, guid: 1661ce2a8a3cdfd3480c3d24bddd72f2, type: 3}
propertyPath: m_LocalRotation.y
value: 0.38268343
objectReference: {fileID: 0}
- target: {fileID: 4283901937423508, guid: 1661ce2a8a3cdfd3480c3d24bddd72f2, type: 3}
propertyPath: m_LocalRotation.z
value: -0
objectReference: {fileID: 0}
- target: {fileID: 4283901937423508, guid: 1661ce2a8a3cdfd3480c3d24bddd72f2, type: 3}
propertyPath: m_LocalRotation.w
value: 0.92387956
objectReference: {fileID: 0}
- target: {fileID: 4283901937423508, guid: 1661ce2a8a3cdfd3480c3d24bddd72f2, type: 3}
propertyPath: m_RootOrder
value: 2
objectReference: {fileID: 0}
- target: {fileID: 4283901937423508, guid: 1661ce2a8a3cdfd3480c3d24bddd72f2, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4283901937423508, guid: 1661ce2a8a3cdfd3480c3d24bddd72f2, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 45
objectReference: {fileID: 0}
- target: {fileID: 4283901937423508, guid: 1661ce2a8a3cdfd3480c3d24bddd72f2, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 114824265617332224, guid: 1661ce2a8a3cdfd3480c3d24bddd72f2,
type: 3}
propertyPath: m_Enabled
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2237312266892387086, guid: 1661ce2a8a3cdfd3480c3d24bddd72f2,
type: 3}
propertyPath: m_Immovable
value: 1
objectReference: {fileID: 0}
- target: {fileID: 9178360820360622353, guid: 1661ce2a8a3cdfd3480c3d24bddd72f2,
type: 3}
propertyPath: m_LocalScale.x
value: 1
objectReference: {fileID: 0}
- target: {fileID: 9178360820360622353, guid: 1661ce2a8a3cdfd3480c3d24bddd72f2,
type: 3}
propertyPath: m_LocalScale.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 9178360820360622353, guid: 1661ce2a8a3cdfd3480c3d24bddd72f2,
type: 3}
propertyPath: m_LocalScale.z
value: 1
objectReference: {fileID: 0}
- target: {fileID: 952006233201449903, guid: 1661ce2a8a3cdfd3480c3d24bddd72f2,
type: 3}
propertyPath: m_AnchorPosition.y
value: -0.17
objectReference: {fileID: 0}
- target: {fileID: 952006233201449903, guid: 1661ce2a8a3cdfd3480c3d24bddd72f2,
type: 3}
propertyPath: m_AnchorPosition.x
value: -0.34
objectReference: {fileID: 0}
- target: {fileID: 952006233201449903, guid: 1661ce2a8a3cdfd3480c3d24bddd72f2,
type: 3}
propertyPath: m_AnchorPosition.z
value: -0.34
objectReference: {fileID: 0}
- target: {fileID: 952006233201449903, guid: 1661ce2a8a3cdfd3480c3d24bddd72f2,
type: 3}
propertyPath: m_AnchorRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 952006233201449903, guid: 1661ce2a8a3cdfd3480c3d24bddd72f2,
type: 3}
propertyPath: m_AnchorRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 952006233201449903, guid: 1661ce2a8a3cdfd3480c3d24bddd72f2,
type: 3}
propertyPath: m_ParentAnchorPosition.x
value: 0.34000003
objectReference: {fileID: 0}
- target: {fileID: 952006233201449903, guid: 1661ce2a8a3cdfd3480c3d24bddd72f2,
type: 3}
propertyPath: m_ParentAnchorPosition.y
value: -0.16999991
objectReference: {fileID: 0}
- target: {fileID: 952006233201449903, guid: 1661ce2a8a3cdfd3480c3d24bddd72f2,
type: 3}
propertyPath: m_ParentAnchorPosition.z
value: -0.34000003
objectReference: {fileID: 0}
- target: {fileID: 952006233201449903, guid: 1661ce2a8a3cdfd3480c3d24bddd72f2,
type: 3}
propertyPath: m_ParentAnchorRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 952006233201449903, guid: 1661ce2a8a3cdfd3480c3d24bddd72f2,
type: 3}
propertyPath: m_ParentAnchorRotation.y
value: -0.7071068
objectReference: {fileID: 0}
- target: {fileID: 952006233201449903, guid: 1661ce2a8a3cdfd3480c3d24bddd72f2,
type: 3}
propertyPath: m_ParentAnchorRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 952006233201449903, guid: 1661ce2a8a3cdfd3480c3d24bddd72f2,
type: 3}
propertyPath: m_ParentAnchorRotation.w
value: 0.70710695
objectReference: {fileID: 0}
- target: {fileID: 952006233201449903, guid: 1661ce2a8a3cdfd3480c3d24bddd72f2,
type: 3}
propertyPath: m_Swing1
value: 1
objectReference: {fileID: 0}
- target: {fileID: 952006233201449903, guid: 1661ce2a8a3cdfd3480c3d24bddd72f2,
type: 3}
propertyPath: m_Swing2
value: 1
objectReference: {fileID: 0}
- target: {fileID: 952006233201449903, guid: 1661ce2a8a3cdfd3480c3d24bddd72f2,
type: 3}
propertyPath: m_XDrive.lowerLimit
value: -120
objectReference: {fileID: 0}
- target: {fileID: 952006233201449903, guid: 1661ce2a8a3cdfd3480c3d24bddd72f2,
type: 3}
propertyPath: m_YDrive.lowerLimit
value: -120
objectReference: {fileID: 0}
- target: {fileID: 952006233201449903, guid: 1661ce2a8a3cdfd3480c3d24bddd72f2,
type: 3}
propertyPath: m_YDrive.upperLimit
value: 120
objectReference: {fileID: 0}
- target: {fileID: 952006233201449903, guid: 1661ce2a8a3cdfd3480c3d24bddd72f2,
type: 3}
propertyPath: m_XDrive.upperLimit
value: 120
objectReference: {fileID: 0}
- target: {fileID: 952006233201449903, guid: 1661ce2a8a3cdfd3480c3d24bddd72f2,
type: 3}
propertyPath: m_ZDrive.lowerLimit
value: -120
objectReference: {fileID: 0}
- target: {fileID: 952006233201449903, guid: 1661ce2a8a3cdfd3480c3d24bddd72f2,
type: 3}
propertyPath: m_ZDrive.upperLimit
value: 120
objectReference: {fileID: 0}
- target: {fileID: 8640153343578765727, guid: 1661ce2a8a3cdfd3480c3d24bddd72f2,
type: 3}
propertyPath: m_Name
value: ForeLegBone0
objectReference: {fileID: 0}
- target: {fileID: 75375539162916863, guid: 1661ce2a8a3cdfd3480c3d24bddd72f2,
type: 3}
propertyPath: m_AnchorPosition.y
value: -0
objectReference: {fileID: 0}
- target: {fileID: 75375539162916863, guid: 1661ce2a8a3cdfd3480c3d24bddd72f2,
type: 3}
propertyPath: m_AnchorRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 75375539162916863, guid: 1661ce2a8a3cdfd3480c3d24bddd72f2,
type: 3}
propertyPath: m_AnchorRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 75375539162916863, guid: 1661ce2a8a3cdfd3480c3d24bddd72f2,
type: 3}
propertyPath: m_AnchorPosition.x
value: -0.62
objectReference: {fileID: 0}
- target: {fileID: 75375539162916863, guid: 1661ce2a8a3cdfd3480c3d24bddd72f2,
type: 3}
propertyPath: m_AnchorPosition.z
value: -0.82
objectReference: {fileID: 0}
- target: {fileID: 75375539162916863, guid: 1661ce2a8a3cdfd3480c3d24bddd72f2,
type: 3}
propertyPath: m_ParentAnchorPosition.x
value: -0.9852712
objectReference: {fileID: 0}
- target: {fileID: 75375539162916863, guid: 1661ce2a8a3cdfd3480c3d24bddd72f2,
type: 3}
propertyPath: m_ParentAnchorPosition.y
value: -0.15444617
objectReference: {fileID: 0}
- target: {fileID: 75375539162916863, guid: 1661ce2a8a3cdfd3480c3d24bddd72f2,
type: 3}
propertyPath: m_ParentAnchorPosition.z
value: -0.94548225
objectReference: {fileID: 0}
- target: {fileID: 75375539162916863, guid: 1661ce2a8a3cdfd3480c3d24bddd72f2,
type: 3}
propertyPath: m_ParentAnchorRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 75375539162916863, guid: 1661ce2a8a3cdfd3480c3d24bddd72f2,
type: 3}
propertyPath: m_ParentAnchorRotation.w
value: 1.0000002
objectReference: {fileID: 0}
- target: {fileID: 75375539162916863, guid: 1661ce2a8a3cdfd3480c3d24bddd72f2,
type: 3}
propertyPath: m_XDrive.upperLimit
value: 120
objectReference: {fileID: 0}
- target: {fileID: 75375539162916863, guid: 1661ce2a8a3cdfd3480c3d24bddd72f2,
type: 3}
propertyPath: m_Swing1
value: 2
objectReference: {fileID: 0}
- target: {fileID: 75375539162916863, guid: 1661ce2a8a3cdfd3480c3d24bddd72f2,
type: 3}
propertyPath: m_Swing2
value: 2
objectReference: {fileID: 0}
- target: {fileID: 75375539162916863, guid: 1661ce2a8a3cdfd3480c3d24bddd72f2,
type: 3}
propertyPath: m_XDrive.lowerLimit
value: -120
objectReference: {fileID: 0}
- target: {fileID: 75375539162916863, guid: 1661ce2a8a3cdfd3480c3d24bddd72f2,
type: 3}
propertyPath: m_YDrive.lowerLimit
value: -120
objectReference: {fileID: 0}
- target: {fileID: 75375539162916863, guid: 1661ce2a8a3cdfd3480c3d24bddd72f2,
type: 3}
propertyPath: m_YDrive.upperLimit
value: 120
objectReference: {fileID: 0}
- target: {fileID: 75375539162916863, guid: 1661ce2a8a3cdfd3480c3d24bddd72f2,
type: 3}
propertyPath: m_ZDrive.lowerLimit
value: -120
objectReference: {fileID: 0}
- target: {fileID: 75375539162916863, guid: 1661ce2a8a3cdfd3480c3d24bddd72f2,
type: 3}
propertyPath: m_ZDrive.upperLimit
value: 120
objectReference: {fileID: 0}
- target: {fileID: 7737080709538424164, guid: 1661ce2a8a3cdfd3480c3d24bddd72f2,
type: 3}
propertyPath: m_Enabled
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 1661ce2a8a3cdfd3480c3d24bddd72f2, type: 3}
--- !u!1 &1903117048 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 8640153343578765727, guid: 1661ce2a8a3cdfd3480c3d24bddd72f2,
type: 3}
m_PrefabInstance: {fileID: 1445410834}
m_PrefabAsset: {fileID: 0}
--- !u!1 &1932203904 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 1129387478859796, guid: 1661ce2a8a3cdfd3480c3d24bddd72f2,
type: 3}
m_PrefabInstance: {fileID: 1445410834}
m_PrefabAsset: {fileID: 0}
--- !u!114 &1932203905
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1932203904}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 1183164ed37748bf9cc8441ceb64df13, type: 3}
m_Name:
m_EditorClassIdentifier:
upperLeg: {fileID: 1167278637}
foreLeg: {fileID: 1903117048}
useAlternativeKeySetForInput: 0
maxJointForceLimit: 10000
maxJointSpring: 40
jointDampen: 3000
currentStrength: 0

7
UnitySDK/Assets/ML-Agents/Examples/Crawler/Scenes/ArticulatedCrawlerManualControl.unity.meta


fileFormatVersion: 2
guid: 580ab7b7069371d8f89491f844c543a0
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

1001
UnitySDK/Assets/ML-Agents/Examples/Crawler/Scenes/ArticulatedCrawlerStaticTarget.unity
文件差异内容过多而无法显示
查看文件

7
UnitySDK/Assets/ML-Agents/Examples/Crawler/Scenes/ArticulatedCrawlerStaticTarget.unity.meta


fileFormatVersion: 2
guid: 6368b7768f89e5a2ea6aa0120235c949
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

167
UnitySDK/Assets/ML-Agents/Examples/Crawler/Scripts/ArticulatedCrawlerManualControl.cs


using System;
using UnityEngine;
namespace MLAgents
{
public class ArticulatedCrawlerManualControl : MonoBehaviour
{
public GameObject upperLeg;
public GameObject foreLeg;
private ArticulationBody m_AbUpper;
private ArticulationBody m_AbFore;
private Vector3 m_rotationUpper;
private Vector3 m_rotationFore;
public bool useAlternativeKeySetForInput = false;
public float maxJointForceLimit = 1000;
public float maxJointSpring = 40;
public float jointDampen = 3000;
public float currentStrength = 0.0f;
/// <summary>
/// Collect the rigidbodies of the reacher in order to resue them for
/// observations and actions.
/// </summary>
public void Start()
{
m_AbUpper = upperLeg.GetComponent<ArticulationBody>();
m_AbFore = foreLeg.GetComponent<ArticulationBody>();
m_rotationUpper = m_rotationFore = Vector3.zero;
}
/// <summary>
/// Resets the position and velocity of the agent and the goal.
/// </summary>
public void AgentReset()
{
m_rotationUpper = Vector3.zero;
m_rotationFore = Vector3.zero;
/*
m_AbUpper.transform.position = new Vector3(0f, -4f, 0f) + transform.position;
m_AbFore.transform.rotation = Quaternion.Euler(180f, 0f, 0f);
pendulumB.transform.position = new Vector3(0f, -10f, 0f) + transform.position;
pendulumB.transform.rotation = Quaternion.Euler(180f, 0f, 0f);
*/
}
public void FixedUpdate()
{
//float maxTorque = 1000f;
float deltaRotation = 0.01f;
// upper arm
if (Input.GetKey(KeyCode.A))
m_rotationUpper.x += deltaRotation;
if (Input.GetKey(KeyCode.Z))
m_rotationUpper.x -= deltaRotation;
if (Input.GetKey(KeyCode.S))
m_rotationUpper.y += deltaRotation;
if (Input.GetKey(KeyCode.X))
m_rotationUpper.y -= deltaRotation;
if (Input.GetKey(KeyCode.D))
m_rotationUpper.z += deltaRotation;
if (Input.GetKey(KeyCode.C))
m_rotationUpper.z -= deltaRotation;
m_rotationUpper.x = Mathf.Clamp(m_rotationUpper.x, -Mathf.PI * 0.5f, Mathf.PI * 0.5f);
m_rotationUpper.y = Mathf.Clamp(m_rotationUpper.y, -Mathf.PI * 0.5f, Mathf.PI * 0.5f);
m_rotationUpper.z = Mathf.Clamp(m_rotationUpper.z, -Mathf.PI * 0.5f, Mathf.PI * 0.5f);
// lower arm
if (Input.GetKey(KeyCode.F))
m_rotationFore.x += deltaRotation;
if (Input.GetKey(KeyCode.V))
m_rotationFore.x -= deltaRotation;
if (Input.GetKey(KeyCode.G))
m_rotationFore.y += deltaRotation;
if (Input.GetKey(KeyCode.B))
m_rotationFore.y -= deltaRotation;
if (Input.GetKey(KeyCode.H))
m_rotationFore.z += deltaRotation;
if (Input.GetKey(KeyCode.N))
m_rotationFore.z -= deltaRotation;
m_rotationFore.x = Mathf.Clamp(m_rotationFore.x, -Mathf.PI * 0.5f, Mathf.PI * 0.5f);
m_rotationFore.y = Mathf.Clamp(m_rotationFore.y, -Mathf.PI * 0.5f, Mathf.PI * 0.5f);
m_rotationFore.z = Mathf.Clamp(m_rotationFore.z, -Mathf.PI * 0.5f, Mathf.PI * 0.5f);
SetJointTargetRotation(m_AbUpper, m_rotationUpper.x, m_rotationUpper.y, m_rotationUpper.z);
SetJointStrength(m_AbUpper, 0.0001f);
SetJointTargetRotation(m_AbFore, m_rotationFore.x, m_rotationFore.y, m_rotationFore.z);
SetJointStrength(m_AbFore, 0.0001f);
if (Input.GetKey(KeyCode.Escape))
AgentReset();
}
public void SetJointTargetRotation(ArticulationBody arb, float x, float y, float z)
{
/*
// Incoming values need to be in [-1,1] interval
x = (x + 1f) * 0.5f;
y = (y + 1f) * 0.5f;
z = (z + 1f) * 0.5f;
*/
var xDrive = arb.xDrive;
var yDrive = arb.yDrive;
var zDrive = arb.zDrive;
/*
var xRot = Mathf.Lerp(xDrive.lowerLimit, xDrive.upperLimit, x);
var yRot = Mathf.Lerp(yDrive.lowerLimit, yDrive.upperLimit, y);
var zRot = Mathf.Lerp(zDrive.lowerLimit, zDrive.upperLimit, z);
var currentXNormalizedRot =
Mathf.InverseLerp(xDrive.lowerLimit, xDrive.upperLimit, xRot);
// What is this ? Vilmantas Why lowerLimit is not used ?
var currentYNormalizedRot = Mathf.InverseLerp(yDrive.lowerLimit, yDrive.upperLimit, yRot);
var currentZNormalizedRot = Mathf.InverseLerp(zDrive.lowerLimit, zDrive.upperLimit, zRot);
//joint.targetRotation = Quaternion.Euler(xRot, yRot, zRot); // Original code
*/
var xRot = x;
var yRot = y;
var zRot = z;
xDrive.target = xRot; yDrive.target = yRot; zDrive.target = zRot;
arb.xDrive = xDrive; arb.yDrive = yDrive; arb.zDrive = zDrive;
var currentEularJointRotation = new Vector3(xRot, yRot, zRot);
}
public void SetJointStrength(ArticulationBody arb, float strength)
{
var xDrive = arb.xDrive;
var yDrive = arb.yDrive;
var zDrive = arb.zDrive;
var rawVal = (strength + 1f) * 0.5f * maxJointForceLimit;
xDrive.stiffness = yDrive.stiffness = zDrive.stiffness = maxJointSpring;
xDrive.damping = yDrive.damping = zDrive.damping = jointDampen;
xDrive.forceLimit = yDrive.forceLimit = zDrive.forceLimit = rawVal;
// Slerp drive does not exist, so we try to set strength for each axis individually
arb.xDrive = xDrive;
arb.yDrive = yDrive;
arb.zDrive = zDrive;
//joint.slerpDrive = jd;
currentStrength = rawVal;
}
}
}

3
UnitySDK/Assets/ML-Agents/Examples/Crawler/Scripts/ArticulatedCrawlerManualControl.cs.meta


fileFormatVersion: 2
guid: 1183164ed37748bf9cc8441ceb64df13
timeCreated: 1572947634
正在加载...
取消
保存