# Line Sensor



# Working Environment

<H4>Tools:</H4>

* Enveronment: ``PlatformIO``

* Framework: ``Arduino``

* Code editor: ``Visual Studio Code``


<H4>Hardware:</H4>

* Mcu: ``STM32G030C8T6``
* Magnetic Sensor: ``QMC5883``

# How to build and Flash

Setup Visual studio Code
--------------------------
The VS code setup Instructions are available in <a href="https://code.visualstudio.com/docs">Getting Started</a>.
* Setup Visual studio code according to the Host operating system. </a>
* Install <a href="https://docs.platformio.org/en/latest/integration/ide/vscode.html#ide-vscode">PlatformIo</a> extension inside VS code
* Install <a href="https://docs.platformio.org/en/latest/platforms/ststm32.html">STM32 Platform</a> in PlatformIo
* Install Board support packages for STM32G0C038T6
* Select the board and Framework as Arduino

Building and Flashing Application:
----------------------
To build the application, clone the `affbotics_software` repo and go to the folder `Line_sensor`
* Pull the <a href="https://github.com/baseapp/affbotics_software">repository</a> locally
* Navigate to the directory ``affbotics_software/firmware/avg/Line_sensor/``
* Select the COM port
* Click Upload

# Program Flow

Basic Workflow:
----------------

Firmware is present in ``affbotics_software/firmware/avg/Line_sensor/src/main.cpp``
* Line sensor communicates using Modbus over RS485
* The Modbus I registers from address ``0X1000`` to ``0X1003`` can be read to obtain number of tracks, markers, Left track error and Right track error

Am a Geek:
------------
* Modbus Register address and ``SLAVE_ID`` can be changed by changing ``#define`` values 
* Uncomment the line `` #define DEBUGMODE 1`` to continuously print raw sensor readings in CSV format through serial.
* Track and marker threshold values can be tweaked by changing ``#define trackThreshold`` and ``#define markerThreshold``

# Experiments

### Nov-25-2022
#### NFC tests
 - We have tested the possibility of having some instructions flashed into the NFC tags so that the AGV can read and process the data on the fly, but it turns out that its only possible while the AGV is moving slowly otherwise it can't read the data reliably. [image](https://cdn.discordapp.com/attachments/884335599962693633/1045657879593635850/image.png)