Skip to content

Latest commit

 

History

History
169 lines (102 loc) · 5.83 KB

tech_doc.md

File metadata and controls

169 lines (102 loc) · 5.83 KB

Tech Design for Arduino Dome Controller Code

Creator: Latifah Maasarani ([email protected])

Last Update: Latifah M, August 8, 2017


Data types, functions, states, etc are bolded

Variables are bulleted with their type in blue

Comment information is italicized

If highlighted, not yet implemented in code

This is PSEUDOcode, only explains the State Machine, do not copy paste into IDE

Objects (Structs)

SensorInfo: Two global variables for this type: sensorInfo.Gear & sensorInfo.Dome

  • Int inputPin
  • Int count
  • Bool lastState
  • Char counterName

DomeInfo : One global variable of this type: domeInfo

  • float relativePosition (e.g. -40 degrees) -Number of degrees needed to move CW(positive) or CCW(negative)
  • float absolutePosition (e.g. 320 degrees) -corresponds to azimuth position of telescope
  • float gearCountPerDomeDegree -number of hits of the gear sensor corresponding to one degree of dome rotation

MotorMovementInfo: Single global for this type: motorMovementInfo

  • int turningDirection -Tells motor which direction to turn (i.e. CW/CCW or FORWARD/BACKWARD)
  • int gearCountsToTarget -Relative number of degrees needed to move to reach wanted absolute position

CommandInfo (Single global of this type)

  • char buffer[BUFFER_SIZE]

    -BUFFER_SIZE is # defined

    -Where serial characters are temporarily stored so commands can be read using function readCommands

  • int index

  • bool hasData

ShutterMovementInfo : single global type: shutterMovementInfo

State Machine

Idle State

-The base state we start in and always return to eventually

-Implemented in case there is code that needs to be read before entering into a different state

Calibration State -Turns the motor in one direction while pumping updateCounter function for both sensors

-Once dome has completed one full rotation, enter END_CALIBRATION_STATE

End Calibration State

-Calculates the Gear rotation count per dome degree and saves in to domeInfo struct (domeInfo.gearCountPerDomeDegree) (needs to be devided by 360 for implementation, dividing by small number for debugging code)

-when finished, make currentState = IDLE_STATE

Motor Turning State

-will be used to tell the dome which direction to turn and how far to rotate

End Motor Turning State

-Send “finished moving” command to driver

-set currentState = IDLE_STATE when finished

Functions

Void serialEvent():

  • Reads data from the serial connection immediately when data sent.
  • Built in function (https://www.arduino.cc/en/Tutorial/SerialEvent)
  • creates array from command read
  • calls readCommands function
  • ends by calling clearCommands function

Void readCommands():

  • Reads array from serialEvent if the command begins with a “+” and has an array size of 3 or more, and ends in “;” (meaning array positions 0,1,&2 minimum) (Example: +MA23;)
  • if array[1] is C then “handleCalibrateCommand()” function is called
  • if array[1] is M then “handleMovementCommand(commandInfo.bufferData)” function is called
  • if array[1] is G then “handleGetPositionCommand()” function is called
  • if array[1] is P then “handleParkCommand()” function is called

Void clearCommands():

  • resets buffer array to zeroes
  • clears commandInfo variables

bool updateMovement():

  • currently empty

bool updateDeceleration():

  • currently empty
  • may not need since motor is quickly responsive to end movement commands

void handleCalibrateCommand():

void handleMovementCommand():

void handleGetPositionCommand():

  • prints a string of data to be parsed by the driver
  • "#" initializer is our syntax for sending a command from the Arduino to the driver, while the “;” signifies the end of the string

void handleParkCommand():

  • will be used to implement home function in driver

Command Syntax

Start Calibration

  • Command: “+C” from driver will tell Arduino to enter Calibration State ;
  • Calls handleCalibrationCommand

Movement

  • Command: +M from driver will tell Arduino to enter Motor Turning State ;

  • Movement Type can be “A” for absolute or “R” for relative

  • Examples:

    • +MA90; will move to absolute position 90 degrees
    • +MR40; will move 40 degrees clockwise of current position
    • +MR-20; will move 20 degrees counter-clockwise of current position
  • The atoi() function in the standard library will help a LOT here, especially since it can handle negative signs too.

  • Calls handleMovementCommand

Get Position

  • Command: “+G” from driver will tell Arduino to send the current absolute position to driver;
  • Calls handleGetPositionCommand

Park

  • Command: +P;
  • Calls handleParkCommand
  • Park in ASCOM driver is know as “home”

TODO:

  • Optical sensor on dome to detect if its moving.
    • If dome not moving but gear is counting: Stop movement!
  • Absolute & relative positions need to be read as floating point numbers rather than as an integer