Skip to content

Commit

Permalink
Issue #20 add @gsr command to rotate to a step position.
Browse files Browse the repository at this point in the history
  • Loading branch information
NameOfTheDragon committed Nov 30, 2019
1 parent b4a97fa commit cbaf097
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
30 changes: 21 additions & 9 deletions TA.NexDome.Rotator/CommandProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ Response CommandProcessor::HandleCommand(Command& command) const
if (command.Verb == "FR") return HandleFR(command); // Read firmware version
if (command.Verb == "GA") return HandleGA(command); // Goto Azimuth (rotator only)
if (command.Verb == "GH") return HandleGH(command); // Goto Home Sensor (rotator only)
if (command.Verb == "GS") return HandleGS(command); // Goto step position (rotator only)
if (command.Verb == "HR") return HandleHR(command); // Home position Read (rotator only)
if (command.Verb == "HW") return HandleHW(command); // Home position Write (rotator only)
if (command.Verb == "SW") return HandleSW(command); // Stop motor (emergency stop)
Expand Down Expand Up @@ -134,19 +135,30 @@ Response CommandProcessor::HandleAR(Command& command) const
}


void CommandProcessor::rotateToMicrostepPosition(const int32_t target) const {
const auto currentPosition = rotator.getCurrentPosition();
const auto delta = target - currentPosition;
const auto direction = sgn(delta);
if (abs(delta) >= settings.deadZone)
{
HomeSensor::cancelHoming();
sendDirection(direction);
rotator.moveToPosition(target);
}
}

Response CommandProcessor::HandleGA(Command& command) const
{
const auto microstepsPerDegree = settings.home.microstepsPerRotation / 360.0;
const auto target = targetStepPosition(command.StepPosition * microstepsPerDegree);
const auto currentPosition = rotator.getCurrentPosition();
const auto delta = target - currentPosition;
const auto direction = sgn(delta);
if (abs(delta) >= settings.deadZone)
{
HomeSensor::cancelHoming();
sendDirection(direction);
rotator.moveToPosition(target);
}
rotateToMicrostepPosition(target);
return Response::FromSuccessfulCommand(command);
}

Response CommandProcessor::HandleGS(Command& command) const
{
const auto target = targetStepPosition(stepsToMicrosteps(command.StepPosition));
rotateToMicrostepPosition(target);
return Response::FromSuccessfulCommand(command);
}

Expand Down
2 changes: 2 additions & 0 deletions TA.NexDome.Rotator/CommandProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class CommandProcessor
Response HandleAW(Command& command) const; // AW - Acceleration ramp time write
Response HandleFR(Command& command) const; // Firmware version read
Response HandleGA(Command& command) const; // GA - GoTo Azimuth (in degrees).
void rotateToMicrostepPosition(int32_t target) const;
Response HandleGS(Command& command) const; // GS - GoTo Step Position
Response HandleGH(Command& command) const; // Go to home sensor
Response HandleHR(Command& command) const; // Read Home position (steps clockwise from true north)
Response HandleHW(Command& command) const; // Write home position (steps clockwise from true north)
Expand Down

0 comments on commit cbaf097

Please sign in to comment.