Skip to content

Commit 2d82cb1

Browse files
authored
feat: MPM and automation support (#711)
* Removed MPM exception * Re-enable copilot * Removed references to Pathfinder probe and axis count * Fix 3lhm brain surface offset * Cleanup
1 parent ace49e4 commit 2d82cb1

File tree

7 files changed

+40
-230
lines changed

7 files changed

+40
-230
lines changed

Assets/Prefabs/UI/SettingsMenu/Menus/EphysLinkMenu.prefab

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4330,7 +4330,7 @@ MonoBehaviour:
43304330
m_PressedTrigger: Pressed
43314331
m_SelectedTrigger: Selected
43324332
m_DisabledTrigger: Disabled
4333-
m_Interactable: 0
4333+
m_Interactable: 1
43344334
m_TargetGraphic: {fileID: 6487466997665187127}
43354335
toggleTransition: 1
43364336
graphic: {fileID: 2477337667047670143}

Assets/Scripts/Pinpoint/CoordinateSystems/PathfinderSpace.cs

Lines changed: 0 additions & 37 deletions
This file was deleted.

Assets/Scripts/Pinpoint/CoordinateSystems/PathfinderSpace.cs.meta

Lines changed: 0 additions & 11 deletions
This file was deleted.

Assets/Scripts/Pinpoint/Probes/ManipulatorBehaviorController.cs

Lines changed: 36 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -156,16 +156,16 @@ private void OnDisable()
156156

157157
public void Initialize(string manipulatorID, bool calibrated)
158158
{
159-
CommunicationManager.Instance.GetManipulators(reponse =>
159+
CommunicationManager.Instance.GetManipulators(response =>
160160
{
161161
// Shortcut exit if we have an invalid manipulator ID
162-
if (!reponse.Manipulators.Contains(manipulatorID))
162+
if (!response.Manipulators.Contains(manipulatorID))
163163
return;
164164

165165
// Set manipulator ID, number of axes, and dimensions
166166
ManipulatorID = manipulatorID;
167-
NumAxes = reponse.NumAxes;
168-
Dimensions = reponse.Dimensions;
167+
NumAxes = response.NumAxes;
168+
Dimensions = response.Dimensions;
169169

170170
// Update transform and space
171171
UpdateSpaceAndTransform();
@@ -191,20 +191,9 @@ void StartEchoing()
191191
});
192192
}
193193

194-
public void Deinitialize()
195-
{
196-
// Destroy Pathfinder probe.
197-
if (NumAxes == -1)
198-
DestroyThisProbe.Invoke();
199-
}
200-
201194
private void UpdateSpaceAndTransform()
202195
{
203-
CoordinateSpace = NumAxes switch
204-
{
205-
-1 => new PathfinderSpace(),
206-
_ => new ManipulatorSpace(Dimensions)
207-
};
196+
CoordinateSpace = new ManipulatorSpace(Dimensions);
208197
CoordinateTransform = NumAxes switch
209198
{
210199
4
@@ -339,6 +328,7 @@ public void MoveByWorldSpaceDelta(
339328
),
340329
newPos =>
341330
{
331+
print("New pos: " + newPos + "; Setting depth...");
342332
// Process depth movement
343333
var targetDepth = newPos.w + manipulatorSpaceDepth;
344334
// Move the manipulator
@@ -391,143 +381,66 @@ Action<string> onErrorCallBack
391381

392382
private void EchoPosition(Vector4 pos)
393383
{
384+
// Exit if disabled and there is no probe controller.
394385
if (!enabled && _probeController == null)
395386
return;
396387

397-
// Check for special Pathfinder mode
398-
if (NumAxes == -1)
399-
{
400-
// Check if probe type changed
401-
CommunicationManager.Instance.GetShankCount(
402-
ManipulatorID,
403-
shankCount =>
404-
{
405-
// Use 2.4 if 4 shank, otherwise default to 1
406-
var probeType =
407-
shankCount == 4
408-
? ProbeProperties.ProbeType.Neuropixels24
409-
: ProbeProperties.ProbeType.Neuropixels1;
410-
411-
// print("Read type: " + probeType + "; Current type: " + _probeManager.ProbeType);
412-
// Check if change is needed
413-
if (probeType != _probeManager.ProbeType)
414-
{
415-
// Unregister manipulator
416-
_probeManager.SetIsEphysLinkControlled(
417-
false,
418-
ManipulatorID,
419-
true,
420-
() =>
421-
{
422-
// Create new probe
423-
CreatePathfinderProbe.Invoke(probeType);
424-
425-
// Destroy current probe
426-
DestroyThisProbe.Invoke();
427-
},
428-
Debug.LogError
429-
);
430-
431-
// Exit early as this probe no longer exists
432-
return;
433-
}
434-
435-
// Otherwise, update probe angles
436-
CommunicationManager.Instance.GetAngles(
437-
ManipulatorID,
438-
angles =>
439-
{
440-
_probeController.SetProbeAngles(
441-
new Vector3(angles.x, 90 - angles.y, angles.z)
442-
);
443-
444-
// If only the DV axis moved, then we drop on DV. Otherwise, we drop on depth.
445-
if (Math.Abs(pos.z - _lastManipulatorPosition.z) > 0.0001)
446-
IsSetToDropToSurfaceWithDepth =
447-
Math.Abs(pos.x - _lastManipulatorPosition.x) > 0.0001
448-
|| Math.Abs(pos.y - _lastManipulatorPosition.y) > 0.0001;
449-
450-
// Copy in new 3-axis position into saved 4-axis position
451-
_lastManipulatorPosition = new Vector4(
452-
pos.x,
453-
pos.y,
454-
pos.z,
455-
_lastManipulatorPosition.w
456-
);
457-
458-
// Apply brain surface offset on correct axis
459-
var brainSurfaceAdjustment = float.IsNaN(BrainSurfaceOffset)
460-
? 0
461-
: BrainSurfaceOffset;
462-
if (IsSetToDropToSurfaceWithDepth)
463-
_lastManipulatorPosition.w -= brainSurfaceAdjustment;
464-
else
465-
_lastManipulatorPosition.z -= brainSurfaceAdjustment;
466-
467-
// Convert Pathfinder space coordinates into active atlas space
468-
var convertedPos = _probeController.Insertion.World2T_Vector(
469-
CoordinateSpace.Space2World_Vector(_lastManipulatorPosition)
470-
);
471-
472-
// Copy and add 4th axis back in
473-
_probeController.SetProbePosition(
474-
new Vector4(
475-
convertedPos.x,
476-
convertedPos.y,
477-
convertedPos.z,
478-
_lastManipulatorPosition.w
479-
)
480-
);
481-
482-
// Log and continue echoing
483-
LogAndContinue();
484-
},
485-
Debug.LogError
486-
);
487-
},
488-
Debug.LogError
489-
);
490-
491-
// Exit early as we've handled Pathfinder
492-
return;
493-
}
494-
495388
// Calculate last used direction for dropping to brain surface (between depth and DV)
496389
var dvDelta = Math.Abs(pos.z - _lastManipulatorPosition.z);
497390
var depthDelta = Math.Abs(pos.w - _lastManipulatorPosition.w);
498391
if (dvDelta > 0.0001 || depthDelta > 0.0001)
499392
IsSetToDropToSurfaceWithDepth = depthDelta > dvDelta;
500393
_lastManipulatorPosition = pos;
501394

502-
// Apply zero coordinate offset
395+
// Apply zero coordinate offset.
503396
var zeroCoordinateAdjustedManipulatorPosition = pos - ZeroCoordinateOffset;
504397

505-
// Convert to coordinate space
398+
// Convert to coordinate space.
506399
var manipulatorSpacePosition = CoordinateTransform.T2U(
507400
zeroCoordinateAdjustedManipulatorPosition
508401
);
509402

510-
// Brain surface adjustment
403+
// Brain surface adjustment.
511404
var brainSurfaceAdjustment = float.IsNaN(BrainSurfaceOffset) ? 0 : BrainSurfaceOffset;
512405
if (IsSetToDropToSurfaceWithDepth)
513-
zeroCoordinateAdjustedManipulatorPosition.w += brainSurfaceAdjustment;
406+
{
407+
// Apply depth adjustment to manipulator position for non-3 axis manipulators.
408+
if (CoordinateTransform.Prefix != "3lhm")
409+
zeroCoordinateAdjustedManipulatorPosition.w += brainSurfaceAdjustment;
410+
}
514411
else
412+
{
515413
manipulatorSpacePosition.y -= brainSurfaceAdjustment;
414+
}
516415

517-
// Convert to world space
416+
// Convert to world space.
518417
var zeroCoordinateAdjustedWorldPosition = CoordinateSpace.Space2World(
519418
manipulatorSpacePosition
520419
);
521420

522-
// Set probe position (change axes to match probe)
421+
// Set probe position (change axes to match probe).
523422
var transformedApmldv = BrainAtlasManager.World2T_Vector(
524423
zeroCoordinateAdjustedWorldPosition
525424
);
526425

527-
// Split between 3 and 4 axis assignments
426+
// Set probe position.
427+
// For 3-axis manipulators, use depth to adjust brain offset if applying offset on depth.
528428
if (CoordinateTransform.Prefix == "3lhm")
529-
_probeController.SetProbePosition(transformedApmldv);
429+
{
430+
if (IsSetToDropToSurfaceWithDepth)
431+
_probeController.SetProbePosition(
432+
new Vector4(
433+
transformedApmldv.x,
434+
transformedApmldv.y,
435+
transformedApmldv.z,
436+
brainSurfaceAdjustment
437+
)
438+
);
439+
else
440+
_probeController.SetProbePosition(transformedApmldv);
441+
}
530442
else
443+
{
531444
_probeController.SetProbePosition(
532445
new Vector4(
533446
transformedApmldv.x,
@@ -536,6 +449,7 @@ private void EchoPosition(Vector4 pos)
536449
zeroCoordinateAdjustedManipulatorPosition.w
537450
)
538451
);
452+
}
539453

540454
// Log and continue echoing
541455
LogAndContinue();
@@ -551,7 +465,6 @@ void LogAndContinue()
551465
|| Mathf.Abs(positionDifference.z) > 0.0001
552466
|| Mathf.Abs(positionDifference.w) > 0.0001
553467
)
554-
{
555468
// Log every 4 hz
556469
if (Time.time - _lastLoggedTime >= 0.25)
557470
{
@@ -587,7 +500,6 @@ void LogAndContinue()
587500
// Update last logged position
588501
_lastLoggedManipulatorPosition = pos;
589502
}
590-
}
591503

592504
// Continue echoing position
593505
CommunicationManager.Instance.GetPosition(ManipulatorID, EchoPosition);

Assets/Scripts/Pinpoint/Probes/ProbeManager.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1068,7 +1068,6 @@ public void SetIsEphysLinkControlled(
10681068
}
10691069
else
10701070
{
1071-
ManipulatorBehaviorController.Deinitialize();
10721071
IsEphysLinkControlled = false;
10731072
onSuccess?.Invoke();
10741073
}

Assets/Scripts/Pinpoint/UI/EphysLinkSettings/EphysLinkSettings.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -392,9 +392,6 @@ public void ToggleCopilotPanel(bool isEnabled)
392392
public void InvokeShouldUpdateProbesListEvent()
393393
{
394394
ShouldUpdateProbesListEvent.Invoke();
395-
396-
// Enable/Disable Copilot toggle based on if there are any probes that can be controlled by it.
397-
_copilotToggle.interactable = LinkedProbes.Count > 0;
398395
}
399396

400397
#endregion
@@ -436,9 +433,6 @@ var probeManager in ProbeManager.Instances.Where(probeManager =>
436433
false,
437434
probeManager.ManipulatorBehaviorController.ManipulatorID
438435
);
439-
440-
// FIXME: This is done because of race condition with closing out server. Should be fixed with non-registration setup.
441-
probeManager.ManipulatorBehaviorController.Deinitialize();
442436
}
443437

444438
CommunicationManager.Instance.DisconnectFromServer(() =>

0 commit comments

Comments
 (0)