|
42 | 42 |
|
43 | 43 | logger = getLogger()
|
44 | 44 |
|
| 45 | +AcceptedJointTypes = [ |
| 46 | + adsk.fusion.JointTypes.RevoluteJointType, |
| 47 | + adsk.fusion.JointTypes.SliderJointType, |
| 48 | + adsk.fusion.JointTypes.BallJointType, |
| 49 | +] |
45 | 50 |
|
46 | 51 | # Need to take in a graphcontainer
|
47 | 52 | # Need to create a new base node for each Joint Instance
|
@@ -99,57 +104,54 @@ def populateJoints(
|
99 | 104 | _addRigidGroup(joint, assembly)
|
100 | 105 | continue
|
101 | 106 |
|
102 |
| - # for now if it's not a revolute or slider joint ignore it |
103 |
| - if joint.jointMotion.jointType != 1 and joint.jointMotion.jointType != 2: |
104 |
| - continue |
| 107 | + if joint.jointMotion.jointType in AcceptedJointTypes: |
| 108 | + try: |
| 109 | + # Fusion has no instances of joints but lets roll with it anyway |
105 | 110 |
|
106 |
| - try: |
107 |
| - # Fusion has no instances of joints but lets roll with it anyway |
| 111 | + # progressDialog.message = f"Exporting Joint configuration {joint.name}" |
| 112 | + progressDialog.addJoint(joint.name) |
108 | 113 |
|
109 |
| - # progressDialog.message = f"Exporting Joint configuration {joint.name}" |
110 |
| - progressDialog.addJoint(joint.name) |
| 114 | + # create the definition |
| 115 | + joint_definition = joints.joint_definitions[joint.entityToken] |
| 116 | + _addJoint(joint, joint_definition) |
111 | 117 |
|
112 |
| - # create the definition |
113 |
| - joint_definition = joints.joint_definitions[joint.entityToken] |
114 |
| - _addJoint(joint, joint_definition) |
| 118 | + # create the instance of the single definition |
| 119 | + joint_instance = joints.joint_instances[joint.entityToken] |
115 | 120 |
|
116 |
| - # create the instance of the single definition |
117 |
| - joint_instance = joints.joint_instances[joint.entityToken] |
| 121 | + for parse_joints in options.joints: |
| 122 | + if parse_joints.jointToken == joint.entityToken: |
| 123 | + guid = str(uuid.uuid4()) |
| 124 | + signal = signals.signal_map[guid] |
| 125 | + construct_info(joint.name, signal, GUID=guid) |
| 126 | + signal.io = signal_pb2.IOType.OUTPUT |
118 | 127 |
|
119 |
| - for parse_joints in options.joints: |
120 |
| - if parse_joints.jointToken == joint.entityToken: |
121 |
| - guid = str(uuid.uuid4()) |
122 |
| - signal = signals.signal_map[guid] |
123 |
| - construct_info(joint.name, signal, GUID=guid) |
124 |
| - signal.io = signal_pb2.IOType.OUTPUT |
| 128 | + # really could just map the enum to a friggin string |
| 129 | + if parse_joints.signalType != SignalType.PASSIVE and assembly.dynamic: |
| 130 | + if parse_joints.signalType == SignalType.CAN: |
| 131 | + signal.device_type = signal_pb2.DeviceType.CANBUS |
| 132 | + elif parse_joints.signalType == SignalType.PWM: |
| 133 | + signal.device_type = signal_pb2.DeviceType.PWM |
125 | 134 |
|
126 |
| - # really could just map the enum to a friggin string |
127 |
| - if parse_joints.signalType != SignalType.PASSIVE and assembly.dynamic: |
128 |
| - if parse_joints.signalType == SignalType.CAN: |
129 |
| - signal.device_type = signal_pb2.DeviceType.CANBUS |
130 |
| - elif parse_joints.signalType == SignalType.PWM: |
131 |
| - signal.device_type = signal_pb2.DeviceType.PWM |
| 135 | + motor = joints.motor_definitions[joint.entityToken] |
| 136 | + fill_info(motor, joint) |
| 137 | + simple_motor = motor.simple_motor |
| 138 | + simple_motor.stall_torque = parse_joints.force |
| 139 | + simple_motor.max_velocity = parse_joints.speed |
| 140 | + simple_motor.braking_constant = 0.8 # Default for now |
| 141 | + joint_definition.motor_reference = joint.entityToken |
132 | 142 |
|
133 |
| - motor = joints.motor_definitions[joint.entityToken] |
134 |
| - fill_info(motor, joint) |
135 |
| - simple_motor = motor.simple_motor |
136 |
| - simple_motor.stall_torque = parse_joints.force |
137 |
| - simple_motor.max_velocity = parse_joints.speed |
138 |
| - simple_motor.braking_constant = 0.8 # Default for now |
139 |
| - joint_definition.motor_reference = joint.entityToken |
| 143 | + joint_instance.signal_reference = signal.info.GUID |
| 144 | + # else: |
| 145 | + # signals.signal_map.remove(guid) |
140 | 146 |
|
141 |
| - joint_instance.signal_reference = signal.info.GUID |
142 |
| - # else: |
143 |
| - # signals.signal_map.remove(guid) |
| 147 | + _addJointInstance(joint, joint_instance, joint_definition, signals, options) |
144 | 148 |
|
145 |
| - _addJointInstance(joint, joint_instance, joint_definition, signals, options) |
| 149 | + # adds information for joint motion and limits |
| 150 | + _motionFromJoint(joint.jointMotion, joint_definition) |
146 | 151 |
|
147 |
| - # adds information for joint motion and limits |
148 |
| - _motionFromJoint(joint.jointMotion, joint_definition) |
149 |
| - |
150 |
| - except: |
151 |
| - logger.error("Failed:\n{}".format(traceback.format_exc())) |
152 |
| - continue |
| 152 | + except: |
| 153 | + logger.error("Failed:\n{}".format(traceback.format_exc())) |
| 154 | + continue |
153 | 155 |
|
154 | 156 |
|
155 | 157 | def _addJoint(joint: adsk.fusion.Joint, joint_definition: joint_pb2.Joint) -> None:
|
@@ -253,10 +255,10 @@ def _motionFromJoint(fusionMotionDefinition: adsk.fusion.JointMotion, proto_join
|
253 | 255 | 0: notImplementedPlaceholder, # this should be ignored
|
254 | 256 | 1: fillRevoluteJointMotion,
|
255 | 257 | 2: fillSliderJointMotion,
|
256 |
| - 3: notImplementedPlaceholder, # TODO: Implement - Ball Joint at least |
| 258 | + 3: notImplementedPlaceholder, |
257 | 259 | 4: notImplementedPlaceholder, # TODO: Implement
|
258 | 260 | 5: notImplementedPlaceholder, # TODO: Implement
|
259 |
| - 6: notImplementedPlaceholder, # TODO: Implement |
| 261 | + 6: fillBallJointMotion, |
260 | 262 | }
|
261 | 263 |
|
262 | 264 | fillJointMotionFunc = fillJointMotionFuncSwitcher.get(fusionMotionDefinition.jointType, notImplementedPlaceholder)
|
@@ -338,6 +340,83 @@ def fillSliderJointMotion(sliderMotion: adsk.fusion.SliderJointMotion, proto_joi
|
338 | 340 | dof.value = sliderMotion.slideValue
|
339 | 341 |
|
340 | 342 |
|
| 343 | +def fillBallJointMotion(ballMotion: adsk.fusion.BallJointMotion, proto_joint: joint_pb2.Joint) -> None: |
| 344 | + """#### Fill Protobuf ball joint motion data |
| 345 | +
|
| 346 | + Args: |
| 347 | + ballMotion (adsk.fusion.BallJointMotion): Fusion Ball Joint Data |
| 348 | + protoJoint (joint_pb2.Joint): Protobuf joint that is being modified |
| 349 | + """ |
| 350 | + |
| 351 | + # proto_joint.joint_motion_type = joint_pb2.JointMotion.REVOLUTE |
| 352 | + proto_joint.joint_motion_type = joint_pb2.JointMotion.BALL |
| 353 | + customDofs = proto_joint.custom |
| 354 | + |
| 355 | + pitchDof = joint_pb2.DOF() |
| 356 | + pitchDof.name = "pitch" |
| 357 | + pitchDof.axis.x = ballMotion.pitchDirectionVector.x |
| 358 | + pitchDof.axis.y = ballMotion.pitchDirectionVector.y |
| 359 | + pitchDof.axis.z = ballMotion.pitchDirectionVector.z |
| 360 | + if ballMotion.pitchLimits.isMaximumValueEnabled or ballMotion.pitchLimits.isMinimumValueEnabled: |
| 361 | + pitchDof.limits.lower = ballMotion.pitchLimits.minimumValue |
| 362 | + pitchDof.limits.upper = ballMotion.pitchLimits.maximumValue |
| 363 | + pitchDof.value = ballMotion.pitchValue |
| 364 | + customDofs.dofs.append(pitchDof) |
| 365 | + |
| 366 | + yawDof = joint_pb2.DOF() |
| 367 | + yawDof.name = "yaw" |
| 368 | + yawDof.axis.x = ballMotion.yawDirectionVector.x |
| 369 | + yawDof.axis.y = ballMotion.yawDirectionVector.y |
| 370 | + yawDof.axis.z = ballMotion.yawDirectionVector.z |
| 371 | + if ballMotion.yawLimits.isMaximumValueEnabled or ballMotion.yawLimits.isMinimumValueEnabled: |
| 372 | + yawDof.limits.lower = ballMotion.yawLimits.minimumValue |
| 373 | + yawDof.limits.upper = ballMotion.yawLimits.maximumValue |
| 374 | + yawDof.value = ballMotion.yawValue |
| 375 | + customDofs.dofs.append(yawDof) |
| 376 | + |
| 377 | + rollDof = joint_pb2.DOF() |
| 378 | + rollDof.name = "roll" |
| 379 | + rollDof.axis.x = ballMotion.rollDirectionVector.x |
| 380 | + rollDof.axis.y = ballMotion.rollDirectionVector.y |
| 381 | + rollDof.axis.z = ballMotion.rollDirectionVector.z |
| 382 | + if ballMotion.rollLimits.isMaximumValueEnabled or ballMotion.rollLimits.isMinimumValueEnabled: |
| 383 | + rollDof.limits.lower = ballMotion.rollLimits.minimumValue |
| 384 | + rollDof.limits.upper = ballMotion.rollLimits.maximumValue |
| 385 | + rollDof.value = ballMotion.rollValue |
| 386 | + customDofs.dofs.append(rollDof) |
| 387 | + |
| 388 | + # ballMotion. |
| 389 | + |
| 390 | + # dof = proto_joint.rotational.rotational_freedom |
| 391 | + |
| 392 | + # # name |
| 393 | + # # axis |
| 394 | + # # pivot |
| 395 | + # # dynamics |
| 396 | + # # limits |
| 397 | + # # current value |
| 398 | + |
| 399 | + # dof.name = "Rotational Joint" |
| 400 | + |
| 401 | + # dof.value = revoluteMotion.rotationValue |
| 402 | + |
| 403 | + # if revoluteMotion.rotationLimits: |
| 404 | + # dof.limits.lower = revoluteMotion.rotationLimits.minimumValue |
| 405 | + # dof.limits.upper = revoluteMotion.rotationLimits.maximumValue |
| 406 | + |
| 407 | + # rotationAxisVector = revoluteMotion.rotationAxisVector |
| 408 | + # if rotationAxisVector: |
| 409 | + # |
| 410 | + # else: |
| 411 | + # rotationAxis = revoluteMotion.rotationAxis |
| 412 | + # # don't handle 4 for now |
| 413 | + # # There is a bug here https://jira.autodesk.com/browse/FUS-80533 |
| 414 | + # # I have 0 memory of why this is necessary |
| 415 | + # dof.axis.x = int(rotationAxis == 0) |
| 416 | + # dof.axis.y = int(rotationAxis == 2) |
| 417 | + # dof.axis.z = int(rotationAxis == 1) |
| 418 | + |
| 419 | + |
341 | 420 | def notImplementedPlaceholder(*argv: Any) -> None: ...
|
342 | 421 |
|
343 | 422 |
|
|
0 commit comments