# Software Requirements for Whiteboard Writer


## Design documentation
In the design document we have defined five functions that have to be performed.

1. Move marker on board
2. Move Wiper on Board
3. Switch Tools
4. Lift Marker
5. Move carriage

We already decided to not implement the tool switch.
This also means that the wiper is probably not something that is going to be achieved either.
We will split these function into software requirements.

## Move marker on board
The marker is specifically moved by the SCARA.
The SCARA itself is attached to the carriage.
This carriage is then moved in function 5.

Therefore the following things are required:
* The software has to parse the path data. Such that it nows what to draw.
* The software has to control the motors.
* The software has to be able to home the motors.
* The software will implement the feedforward control behavior.
* The software must be able to write data at the correct position independent of the carriage position.

## Lift marker.
The servo will lift the marker. For this the servo needs a PWM signal.
This is purely feedforward.

* The software has to send out the correct PWM signal when the marker needs to be lifted according to the data.

## Move carriage
For this the software has to move the steppermotors such that the carriage moves.
Similar to the move marker on board.
* The software must parse the next plot location.
* The software has to control the motors.
* The software has to be able to home the carriage.
* The software must calculate where the carriage is.

# Required structures.


## Motor driver
The motors are powered themself with stepper controllers.
The controllers have a direction pin and a step pin.

For that I will build a struct in the code with the following assets:
* Step-pin
* Direction-pin
* Max-speed
* Max-acceleration
* Microstep (int = 1, 2, 4, 8, 16, 32)
* Divisions (int = 200)
* Angle
* Velocity
* Homing sensor
* Homing angle

## Path instructions
For the pathing instruction we need to be able to read the next path instructions.
For this we need to be able to store a list with points.
For path instructions it might be useful to look in to [wtk](https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry)
Maybe I can just work with characters and a path for each.
The system must be able to plan positions. Where to write stuff and if the carriage should be moved or only the SCARA.

## Point lib
A point struct is needed.
This struct contains two integers.
We need some point calculations.
Add, subtract, distance, angle etc.
Probably just use [ccVector](https://github.com/jobtalle/ccVector)
or [gb_math.h](https://github.com/gingerBill/gb/blob/master/gb_math.h)


## Kinematics struct
* ArmLengthA float
* Motor motor1
* ArmLengthB float
* Motor motor2
* PullyLocationC Point2D
* Motor motor3
* PullyLocationD Point2D
* Motor motor4

## Inverse kinematics
We need to be able to calculate the angles from the position of the motor.
This is done with the cosine-law.
Also required for the carriage.

## Forward kinematics
We need to be able to calculate the positions from the angles of the motor.
Also required for the carriage.

## Main
The main function has to start everything off course.
It will call the initialisation functions of everything.

## Homing
Before the actual writing, we need to know where my steppers are.
As they do not have a complete reference.
The is done by sensors.
Some sensor will detect the arm in a certain position.
Then we know the actual angle, and can set the actual angle position.

## Sensors
The sensors need to be read and return a boolean.
Currently they are planned to be some light gates, with an analog output.

Struct
* Sensor pin
* Threshold value










