Skip to content

Commit f6cf26d

Browse files
authored
368 bug new scale pitch (#393)
* Return to zero coordinate button * Added stop button to return button * New Scale transforms!!! * Fixed manual control UI bugs, use real zero coordinate
1 parent 2a5908f commit f6cf26d

File tree

8 files changed

+473
-12
lines changed

8 files changed

+473
-12
lines changed

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

Lines changed: 312 additions & 7 deletions
Large diffs are not rendered by default.

Assets/Scripts/Core/CoordinateSystems/NewScaleLeftTransform.cs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,41 @@
22

33
namespace CoordinateTransforms
44
{
5-
public class NewScaleLeftTransform : AffineTransform
5+
public class NewScaleLeftTransform : CoordinateTransform
66
{
7-
public NewScaleLeftTransform(float phi, float theta) : base(Vector3.one, new Vector3(theta, 0, phi))
7+
private readonly Quaternion _inverseRotation;
8+
private readonly Quaternion _rotation;
9+
10+
public NewScaleLeftTransform(float yaw, float pitch)
811
{
12+
var yawRotation = Quaternion.AngleAxis(yaw, Vector3.back);
13+
var pitchRotation = Quaternion.AngleAxis(pitch, yawRotation * Vector3.right);
14+
15+
_rotation = yawRotation * pitchRotation;
16+
_inverseRotation = Quaternion.Inverse(_rotation);
917
}
1018

1119
public override string Name => "New Scale Left";
1220
public override string Prefix => "ns-l";
21+
22+
public override Vector3 Transform2Space(Vector3 coordTransformed)
23+
{
24+
return _inverseRotation * coordTransformed;
25+
}
26+
27+
public override Vector3 Space2Transform(Vector3 coordSpace)
28+
{
29+
return _rotation * coordSpace;
30+
}
31+
32+
public override Vector3 Transform2SpaceAxisChange(Vector3 coordTransformed)
33+
{
34+
return coordTransformed;
35+
}
36+
37+
public override Vector3 Space2TransformAxisChange(Vector3 coordSpace)
38+
{
39+
return coordSpace;
40+
}
1341
}
1442
}

Assets/Scripts/TrajectoryPlanner/Probes/ManipulatorBehaviorController.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public bool IsSetToDropToSurfaceWithDepth
144144
}
145145

146146
public CoordinateSpace CoordinateSpace { get; set; }
147-
public AffineTransform Transform { get; set; }
147+
public CoordinateTransform Transform { get; set; }
148148

149149
public bool IsRightHanded
150150
{
@@ -351,6 +351,12 @@ public void MoveXYZByWorldSpaceDelta(Vector3 worldSpaceDelta, Action<Vector4> on
351351
}, Debug.LogError);
352352
}
353353

354+
/// <summary>
355+
/// Drive manipulator depth by a given delta in world space
356+
/// </summary>
357+
/// <param name="worldSpaceDelta">Distance to drive depth in world space coordinates</param>
358+
/// <param name="onSuccessCallback">Action on success</param>
359+
/// <param name="onErrorCallback">Action on error</param>
354360
public void MoveDepthByWorldSpaceDelta(float worldSpaceDelta, Action<bool> onSuccessCallback, Action<string>
355361
onErrorCallback = null)
356362
{
@@ -379,6 +385,18 @@ public void MoveDepthByWorldSpaceDelta(float worldSpaceDelta, Action<bool> onSuc
379385
}, Debug.LogError);
380386
}
381387

388+
/// <summary>
389+
/// Drive the manipulator back to the zero coordinate position
390+
/// </summary>
391+
/// <param name="onSuccessCallback">Action on success</param>
392+
/// <param name="onErrorCallBack">Action on failure</param>
393+
public void MoveBackToZeroCoordinate(Action<Vector4> onSuccessCallback, Action<string> onErrorCallBack)
394+
{
395+
// Send move command
396+
CommunicationManager.Instance.GotoPos(ManipulatorID, ZeroCoordinateOffset, AUTOMATIC_MOVEMENT_SPEED,
397+
onSuccessCallback, onErrorCallBack);
398+
}
399+
382400
#endregion
383401
}
384402
}

Assets/Scripts/TrajectoryPlanner/UI/EphysLinkSettings/.idea/.idea.EphysLinkSettings.dir/.idea/.gitignore

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Scripts/TrajectoryPlanner/UI/EphysLinkSettings/.idea/.idea.EphysLinkSettings.dir/.idea/encodings.xml

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Scripts/TrajectoryPlanner/UI/EphysLinkSettings/.idea/.idea.EphysLinkSettings.dir/.idea/indexLayout.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Scripts/TrajectoryPlanner/UI/EphysLinkSettings/.idea/.idea.EphysLinkSettings.dir/.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Scripts/TrajectoryPlanner/UI/EphysLinkSettings/ManipulatorConnectionPanel.cs

Lines changed: 81 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@ public void Initialize(EphysLinkSettings settingsMenu, string manipulatorID, str
3030
_manipulatorIdText.text = manipulatorID;
3131
UpdateLinkableProbeOptions();
3232

33+
// FIXME: Dependent on Manipulator Type. Should be standardized by Ephys Link.
34+
// Show or hide handedness dropdown depending on manipulator type
35+
if (type == "new_scale")
36+
{
37+
_handednessDropdown.value = 0;
38+
_handednessGroup.SetActive(false);
39+
}
40+
else
41+
{
42+
_handednessGroup.SetActive(true);
43+
}
44+
3345
// FIXME: Dependent on Manipulator Type. Should be standardized by Ephys Link.
3446
// Apply handedness from memory or default to right handed, also pass along manipulator type
3547
if (_attachedProbe)
@@ -81,6 +93,12 @@ public void OnLinkedProbeSelectionChanged(int value)
8193
// With values != 0, there definitely was an attached probe before
8294
_attachedProbe.SetIsEphysLinkControlled(false, _manipulatorId, onSuccess: () =>
8395
{
96+
// Disable keyboard control
97+
_attachedProbe.ProbeController.ManipulatorKeyboardControl = false;
98+
_enableManualControlToggle.SetIsOnWithoutNotify(false);
99+
100+
101+
// Remove probe from linked probes list
84102
_ephysLinkSettings.LinkedProbes.Remove(_attachedProbe);
85103
_attachedProbe = null;
86104

@@ -93,7 +111,15 @@ public void OnLinkedProbeSelectionChanged(int value)
93111
// Disconnect currently attached probe
94112
if (_attachedProbe)
95113
_attachedProbe.SetIsEphysLinkControlled(false,
96-
onSuccess: () => { _ephysLinkSettings.LinkedProbes.Remove(_attachedProbe); });
114+
onSuccess: () =>
115+
{
116+
// Disable keyboard control
117+
_attachedProbe.ProbeController.ManipulatorKeyboardControl = false;
118+
_enableManualControlToggle.SetIsOnWithoutNotify(false);
119+
120+
// Remove probe from linked probes list
121+
_ephysLinkSettings.LinkedProbes.Remove(_attachedProbe);
122+
});
97123

98124
// Find the new probe and attach it
99125
var selectedProbeUUID = _linkedProbeDropdown.options[value].text;
@@ -182,6 +208,54 @@ public void UpdateKeyboardControlState(bool state)
182208
_attachedProbe.ProbeController.ManipulatorKeyboardControl = false;
183209
Debug.LogError(err);
184210
});
211+
212+
// Enable/disable return to zero coordinate button
213+
_returnToZeroCoordinateButton.interactable = state;
214+
}
215+
216+
/// <summary>
217+
/// Return manipulator back to zero coordinate
218+
/// </summary>
219+
public void ReturnToZeroCoordinate()
220+
{
221+
if (_returningToZeroCoordinate)
222+
{
223+
// Return in progress, should stop
224+
_returnToZeroCoordinateButtonText.text = "Stopping...";
225+
226+
CommunicationManager.Instance.Stop(stopState =>
227+
{
228+
// Update text
229+
_returnToZeroCoordinateButtonText.text =
230+
stopState ? "Return to Zero Coordinate" : "Failed to Stop, Try Again";
231+
232+
// Re-enable keyboard control if stop was successful
233+
_attachedProbe.ProbeController.ManipulatorKeyboardControl = stopState;
234+
235+
// Update flag
236+
_returningToZeroCoordinate = !stopState;
237+
});
238+
}
239+
else
240+
{
241+
// Disable keyboard control
242+
_attachedProbe.ProbeController.ManipulatorKeyboardControl = false;
243+
244+
// Set button text and update flag
245+
_returnToZeroCoordinateButtonText.text = "Stop";
246+
_returningToZeroCoordinate = true;
247+
248+
// Move manipulator back to zero coordinate
249+
_attachedProbe.ManipulatorBehaviorController.MoveBackToZeroCoordinate(_ => PostMoveAction(),
250+
_ => PostMoveAction());
251+
252+
void PostMoveAction()
253+
{
254+
_returnToZeroCoordinateButtonText.text = "Return to Zero Coordinate";
255+
_attachedProbe.ProbeController.ManipulatorKeyboardControl = true;
256+
_returningToZeroCoordinate = false;
257+
}
258+
}
185259
}
186260

187261
#endregion
@@ -269,6 +343,7 @@ private void UpdateBrainSurfaceOffsetInputField(float brainSurfaceOffset)
269343
#region Components
270344

271345
[SerializeField] private TMP_Text _manipulatorIdText;
346+
[SerializeField] private GameObject _handednessGroup;
272347
[SerializeField] private Dropdown _handednessDropdown;
273348
[SerializeField] private Dropdown _linkedProbeDropdown;
274349

@@ -278,7 +353,9 @@ private void UpdateBrainSurfaceOffsetInputField(float brainSurfaceOffset)
278353
[SerializeField] private InputField _zeroCoordinateZInputField;
279354
[SerializeField] private InputField _zeroCoordinateDInputField;
280355
[SerializeField] private InputField _brainSurfaceOffsetInputField;
281-
[SerializeField] private Toggle _keyboardControlToggle;
356+
[SerializeField] private Button _returnToZeroCoordinateButton;
357+
[SerializeField] private Text _returnToZeroCoordinateButtonText;
358+
[SerializeField] private Toggle _enableManualControlToggle;
282359

283360
private ProbeManager _attachedProbe;
284361

@@ -290,6 +367,8 @@ private void UpdateBrainSurfaceOffsetInputField(float brainSurfaceOffset)
290367
private string _manipulatorId;
291368
private string _type;
292369

370+
private bool _returningToZeroCoordinate;
371+
293372
#endregion
294373
}
295374
}

0 commit comments

Comments
 (0)