From 5911ecafccef4c03a6763ed9060dcc7295a51faf Mon Sep 17 00:00:00 2001 From: Alena Kazakova Date: Thu, 30 Nov 2017 19:27:08 +0900 Subject: [PATCH] Update README.md --- README.md | 115 +++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 101 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 377eff2..274cd53 100644 --- a/README.md +++ b/README.md @@ -1,39 +1,47 @@ # Overview -## Guidelines +## Getting Started Get Source Code ``` git clone https://github.com/alkaza/RPiRobot.git ``` -Go to library directory +Update reposidory ``` -cd /home/pi/CityScience/src/lib +git pull ``` -Compile static library +Go to library directory ``` -make all +cd /home/pi/CityScience/src/lib ``` Cleanup static library (if changes were made to static library) ``` make clean ``` +Compile static library +``` +make all +``` Go to source directory ``` cd /home/pi/CityScience/src ``` -Copy static library to working directory +Remove static library from working directory (if changes were made to static library) ``` -sh /home/pi/CityScience/src/scripts/cplib.sh +sh /home/pi/CityScience/src/scripts/rmlib.sh examples ``` -Remove static library from working directory (if changes were made to static library) +Copy static library to examples directory ``` -sh /home/pi/CityScience/src/scripts/rmlib.sh +sh /home/pi/CityScience/src/scripts/cplib.sh examples ``` -Go to working directory +Go to examples directory ``` cd /home/pi/CityScience/src/examples ``` +Cleanup all programs (if changes were made to examples) +``` +make clean +``` Compile all programs ``` make all @@ -42,10 +50,6 @@ Compile one program ``` make sensor ``` -Cleanup program (if changes were made to the program) -``` -rm sensor -``` Run the program ``` sudo ./sensor @@ -55,6 +59,89 @@ Terminate the program Ctrl-C ``` +## Robot Library +### Sample code +``` +#include +#include +#include "robot.h" + +int main(void) +{ + setup(); + + while (1) { + /* Implement here */ + } + + return 0; +} +``` +- **stdio.h** is provides many standard library functions for file input and output +- **wiringPi.h** is a GPIO Interface library for the Raspberry Pi +- **robot.h** is a static library for RPiRobot + +### Setup function +- Must include to run once +- Allows to terminate the program with Ctrl-C +- Initializes WiringPi, ultrasonic sensor and dc motor driver and + +``` +setup (); +``` + +### Infinite loop +Put your main code here to run repeatedly +``` +while (1) { + /* Your code */ +} +``` + +### Calculate distance detected by ultrasonic sensor +``` +calc_dist (); +``` + +### Simple motor control +``` +move (direction, speedA, speedB); +``` + +### Motor control with gradual deceleration +``` +move_slow (direction, speedA, speedB); +``` + +**Recommended speed range**: 70~150 + +### Direction modes +- **FW** – go straight +- **BW** – go back +- **RIGHT** – turn right +- **LEFT** – turn left + + +### Advanced variables +Change until which speed to decelerate (70 by default) +``` +min_speed = speed; +``` +Check the previous direction taken +``` +prev_dir +``` + +### Low-level motor control +Set direction +``` +setDir (direction); +``` +Set speed +``` +setSpeed (speedA, speedB); +``` + ## Experiments - Measuring distance - Going forward and backward