test

Dependencies:   mbed Watchdog

Dependents:   STM32-MC_node

Revision:
0:d383e2dee0f7
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/README.md	Mon Jul 06 17:18:59 2020 +0530
@@ -0,0 +1,179 @@
+# stm32-sensor-base
+STM32-based sensor node that can communicate with AS5045 encoders, JSN-SR04 ultrasonic sensors and transmit data over RS485 interface.Designed to work with ROS (http://wiki.ros.org/Documentation), it has some benefits over default rosserial package (http://wiki.ros.org/rosserial) in large data transmission reliability achieved due to using RS485 interface. Another important note : it can be easily extended in order to add support of other essential sensors. Simplicity of the project is achieved due to using the Mbed OS project that brings real-time features and many other important things
+
+## Table of contents
+* [Information](#info)
+* [Structure of the package](#structure)
+	* [Project folders description](#folders)
+	* [Files explained](#files)
+* [RS485 Library](#rs485)
+	* [Class description](#class-description)
+	* [List of methods](#methods)
+	* [List of fields](#fields)
+* [JSN-SR04 Library](#jsn-sr04)
+	* [Class description](#class-description-1)
+	* [List of methods](#methods-1)
+	* [List of fields](#fields-1)
+* [AS5045 Library](#as5045)
+	* [Class description](#class-description-2)
+	* [List of methods](#methods-2)
+	* [List of fields](#fields-2)
+* [E18_D80NK Library](#e18_d80nk)
+	* [Class description](#class-description-3)
+	* [List of methods](#methods-3)
+	* [List of fields](#fields-3)
+* [Using](#using)
+
+## Info
+* MCU : STM32F103
+* OS : Mbed OS (https://os.mbed.com/mbed-os/)
+
+## Structure
+```
+├── AS5045
+│   ├── AS5045.cpp
+│   └── AS5045.h
+├── doc
+│   └── images
+├── E18_D80NK
+│   ├── E18_D80NK.cpp
+│   └── E18_D80NK.h
+├── JSN_SR04
+│   ├── JSN_SR04.cpp
+│   └── JSN_SR04.h
+├── mbed
+├── ros_lib_melodic
+├── RS485
+│   ├── mbed
+│   ├── mbed.bld
+│   ├── RS485.cpp
+│   └── RS485.h
+├── AS5045.lib
+├── CHANGELOG.md
+├── global.h
+├── JSN_SR04.lib
+├── main.cpp
+├── mbed.bld
+├── mbed_config.h
+├── README.md
+├── ros_lib_melodic.lib
+├── RS485Hardware.h
+└── RS485.lib
+```
+
+### Folders
+* AS5045 : library to work with AS5045 encoders
+* E18_D80NK : allows the node to communicate with the E18-D80NK sensor
+* JSN_SR04 : integration with JSN-SR04 ultrasonic sensors
+* RS485 : data transmission library that initiate data R/W over RS485 serial interface
+* mbed : Mbed OS library
+* ros_lib_melodic : ROS library
+* doc : documentation data
+* images : images to use in the documentation
+
+### Files
+* AS5045.cpp : AS5045 methods implementation
+* AS5045.h : AS5045 header that implements AS5045 class (retrieve data from the encoder)
+* E18_D80NK.h : header which contains a code to communicate with the E18-D80NK sensor
+* E18_D80NK.cpp : methods implementation for the E18_D80NK class
+* JSN_SR04.cpp : JSN-SR04 library methods implementation
+* JSN_SR04.h : header with a class which holds data exchange between STM32 and JSN-SR04 ultrasonic sensor
+* RS485.cpp : RS485 methods implementation
+* RS485.h : data transmission/receiving through RS485
+* AS5045.lib : the encoder library import file
+* global.h : pin settings on an STM32
+* JSN_SR04.lib : the ultrasonic sensor library import file
+* main.cpp : firmware main execution file
+* mbed.bld : the official Mbed 2 C/C++ SDK link
+* mbed_config.h : STM32 Mbed OS configuration file
+* README.md : documentation (this file)
+* ros_lib_melodic.lib : ROS library import
+* RS485Hardware.h : ???
+* RS485.lib : RS485 interface library import
+
+## RS485
+RS485 library uses the most versatile communication standard in the standard series defined by the EIA of the same name to transfer data through it. Library is designed to send data byte-by-byte using predefined pins.
+
+![RS485](doc/images/RS485.png?raw=true "RS485 Class Diagram")
+
+### Class description
+The class establishes input and output pins through Serial base class. Once the pins are ready, the base class handles all data transmissions and the RS485 class is an interface. Data transmission can be performed using \_getc() (receive byte) and \_putc() (send byte).
+
+#### Methods
+* RS485() : sets pins for input/output and CS pin (using base class constructor)
+* \_putc() : sends one byte of data (8 bits)  through RS485 interface
+* \_getc() : receives one byte of data through RS485 interface
+
+#### Fields
+* m_modePin : a pin which sets the mode of transmission
+
+## JSN-SR04
+JSN_SR04 uses ultrasonic sensors connected to the internal timer to get distance to an obstacle. Class JSN_SR04 implements basic functionality to measure distance in mm and cm, set boundaries and start/stop the measurement, check if the new data was obtained.
+
+![JSN-SR04](doc/images/JSN_SR04.png?raw=true "JSN-SR04 Class Diagram")
+
+### Class description
+There is a timer event inside of the class that ( triggerTimeout) trigger the sensor to start receiving data from it once in a period. After triggering, sensor sends a respond (external interrupt trigger is set HIGH) that corresponds to distance to an obstacle (formula for converting is on the 2 page of the datasheet). Measured value is saved inside of the class and can be accessed through getDistance_cm() and getDistance_mm() methods. Freshness of the data can be checked through isNewDataReady().
+
+#### Methods
+* JSN_SR04() : assign pins to be a digital output or interrupt input (measurement works on an interrupt mechanism)
+* startMeasurement() : start the measurement of distance to the next obstacle and attach timer events (to automatically send trigger signal and start measuring time when interrupt signal is high (time in corresponds to distance to an obstacle))
+* getDistance_mm() : get measured distance to the obstacle in mm
+* getDistance_cm() : get measured distance to the obstacle in cm
+* setRanges() : set new min and max distance range (boundaries are in datasheet)
+* getMinRange() : obtain current minimal distance to an obstacle
+* getMaxRange() : obtain current maximal distance to an obstacle
+* isNewDataReady() : check if the old data was overwritten (if it’s new)
+* startTimer() : a method to start the timer
+* stopTimer() : a method to stop the timer
+* init() : class initialization
+* turnOffTrigger() : a method that deactivates the trigger pin output
+
+#### Fields
+* echo : interrupt pin connected to the sensor (input)
+* trigger : trigger signal is sent through this pin (output)
+* timer : timer instance that measures an input signal duration
+* distance : measured value of distance
+* minDistance : lower boundary of measurements
+* maxDistance : upper boundary of measurements
+* triggerTimeout : event on an output signal (to send a precise signal which the sensor needs)
+* echoTimeout : event on an input signal timeout (if the signal is out of measurement range)
+* newDataReady : indicator of new data
+* timerStarted : indicator of starting the timer
+
+## AS5045
+AS5045 library is needed to read a state of the AS5045 encoders through SPI. It contains two files : header and source. There are a class in the header that represents encoder reading implementation. Source file contains functions that read data from the encoders.
+
+![AS5045](doc/images/AS5045.png?raw=true "AS5045 Class Diagram")
+
+### Class description
+After SPI and chip select pin are set, the class can communicate with the encoder. To get the needed data getPosition() methods sets low the CS pin and sends dummy message in order to start communication. Data is received in two separate bytes (lower and upper parts) and then are united into one. getRotation() method returns angle of rotation of the encoder based on the position described earlier (angle can be calculated by multiplying a position with the encoder constant of degrees per one tick (change of position)).
+
+#### Methods
+* AS5045() : assigns output pin to act like a chip select (cs) pin and sets up the SPI (pins and frequency)
+* getPosition() : sends dummy data through the SPI to read encoder’s position halved into two bytes from the encoder (that are joined together and returned)
+* getRotation() : converts current position of the encoder into rotation degrees (that are returned) by multiplying it with known amount of degrees per 1 position (is described in the datasheet)
+
+#### Fields
+* \_spi : SPI instance that allows the class to communicate with the encoder
+* \_cs : chip select pin
+* MAX_VALUE : maximal value that can be transfered from the encoder (max position)
+* CONSTANT : change in angle of the encoder per position
+
+## E18_D80NK
+This library is used to communicate with the E18-D80NK infared sensor. The connection between Raspberry PI and the sensor is only one wire, which is set low, when there is an obstacle and high otherwise.
+
+![E18_D80NK](doc/images/E18_D80NK.png?raw=true "E18_D80NK Class Diagram")
+
+### Class description
+To start actually communicate with the sensor it's necessary to set the right pin (which is connected to the sensor's data pin). And then it's possible to check the state of the sensor using the checkObstacle() method, which returns 0 if there is an obstacle and 1 otherwise.
+
+#### Methods
+* E18_D80NK() : assigns an input pin to communicate with the sensor
+* checkObstacle() : check if there is an obstacle in front of the sensor reading the state of the assigned pin
+
+#### Fields
+* input : digital input pin to communicate with the sensor
+
+## Using
+In progress