Skip to content

Nemam pravo push do hlavniho masteru tak tedy takto ... #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
448e90d
feat: Deffered processing pro klavesy i v konzoli
BuFran Jan 25, 2022
c4ba306
Revert "feat: Deffered processing pro klavesy i v konzoli"
BuFran Jan 25, 2022
0c870cf
feat: AD converter API implemented
BuFran Jan 24, 2022
cbb531d
fix: -Wall
BuFran Jan 26, 2022
c019288
fix: Pedanticky ucitel by mel byt pedanticky zejmena k vlastnim chyba…
BuFran Jan 26, 2022
5c387c9
fix: Pedanticky ucitel by mel ucit dle normy, nevnaset syntaktic suga…
BuFran Jan 26, 2022
4d8bfab
feat: wrong API design
BuFran Jan 26, 2022
96eb382
fix: wrong I2C API design - constructor must never fail !
BuFran Jan 26, 2022
1d2db29
style: Lib utils reorganized
BuFran Jan 26, 2022
dc985ac
fix: Variable can be in some context's const, but mutex is always mut…
BuFran Jan 26, 2022
c21b0f8
Optimalizace buildu
BuFran Jan 26, 2022
1c32447
doc: Documentatio of public libs
BuFran Jan 26, 2022
86d6329
doc: Documentatio of UDP
BuFran Jan 26, 2022
bcbb777
fix: reopened I2C should close previous one
BuFran Jan 26, 2022
ee1fe9a
feat: Logging facility lore dynamic way (automatic flush on destructo…
BuFran Jan 26, 2022
12a46a0
feat: Big simplification of Log
BuFran Jan 27, 2022
1f649e9
feat: Being able to check if the underlying bus is open
BuFran Jan 30, 2022
b61b086
feat: Add possibility to read chip address and bus address
BuFran Jan 30, 2022
a49df99
feat: Add full-featured autoprobing of the chip
BuFran Jan 30, 2022
a596c1e
Merge remote-tracking branch 'origin/master'
BuFran Jan 30, 2022
4f9423b
doc: Make better titlepage
BuFran Jan 31, 2022
3f0e044
feat: Umozneni zmenit adresu GPIO cipu
BuFran Feb 1, 2022
a2f6793
feat: Aplikace transactu bez mezery v komunikaci
BuFran Feb 1, 2022
7632d9a
feat: Pridan join pres iteratory, konverze na fixedpoint
BuFran Feb 19, 2022
f4ff651
feat: Implementace API pro sériovou linku
BuFran Feb 21, 2022
65e9e1b
feat: Pomocné funkce prooperace se stringy
BuFran Feb 21, 2022
976caca
feat: Implementace RAII locale
BuFran Feb 21, 2022
2877b5c
feat: Implementace RAII locale - explicit instantiation chybela
BuFran Feb 21, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ project(RoboUtils VERSION 0.1 LANGUAGES CXX)

include(GNUInstallDirs)
set(CMAKE_CXX_STANDARD 17)
file(GLOB SOURCES src/*.cpp src/io/*.cpp src/comm/*.cpp)
file(GLOB SOURCES src/*.cpp src/*/*.cpp)

file(GLOB HEADERS include/*.h include/io/*.h include/comm/*.h include/chips/*.h)
file(GLOB HEADERS include/*.h include/*/*.h)

add_library(libroboutils ${SOURCES})
add_compile_options(-Wall -Wextra -Werror -Wpedantic)

target_include_directories(libroboutils PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
Expand Down
106 changes: 80 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,98 @@ RoboUtils
=========
C++ classes used for speeding up development of robots, suitable for Raspberry Pi hat KAMBot.

Features classes for:
* UDP
* TCP
* Thread safe variable access
* Thread safe I2C (Linux only)
* Measuring time
* KAMBot periferies access
* PID
* Advanced logging with streams and logging over network

## To be included
* Drivers for KM2 stepper motor driver board with odometry calculations
* PWM driver
* Class for performing preprogrammed robot movement
## Features classes for:

### RoboUtils::IO namespace
* I2C thread-safe driver for RaspberryPi
* ADC using AD7997 chip
* GPIO using MCP23017 chip
* KM2 using KM2 motor controller board
* PWM using xxxx chip (currently not implemented)

### RoboUtils::comm namespace
* UDP driver for transporting strings over network
* TCP driver (not reimplemented)

### RoboUtils::util namespace
* Thread safe variable access
* Measuring time
* Convenient string to list manipulation utility (usable for NMEA parser)

### RoboUtils namespace

* PID
* Advanced logging with streams and logging over network

## What will be NEVER featured:

* The NMEA parser (part of student semestral project)
* The analog preprocessing of line
* The robot wheel kinematics (yep, the hell!)
* The robot controller for line following
* Yep, any part of code the students should develop in the labs in their way that will be examined


## Installation

```
git clone https://github.com/matoushybl/RoboUtils.git
### Using global liborary

```bash
git clone https://student.robotika.ceitec.vutbr.cz/VYUKA/BPC-PRP/RoboUtils.git
cd RoboUtils
cmake . && make install
```

In your project's `CMakeLists.txt`:
```
cmake_minimum_required(VERSION 3.7)
project(MyCoolRobot)

```cMake
find_package(RoboUtils REQUIRED)
set(CMAKE_CXX_STANDARD 14)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")

add_executable(MyCoolRobot main.cpp)
add_executable(<appname> <... src/main.cpp etc ...>)

target_link_libraries(<appname> libroboutils)
```

WARNING: Any future change in API of the lib will disturb all your projects you are using it. The devil who owns
library root will rule all your code.


target_link_libraries(MyCoolRobot libroboutils)
### Using specific branch in Your project (dependency hell issue)

Use this in the case you want to maintain specific version of lib (ie you do not want future library changes to be
ported to your code) This is the case when the library API is changing and you need to maintain a lot of projects
that depends on it. The updating root library from previous example might be a nightmare.

Assume you have project with `CMakeLists.txt` in root directory of you GITted project. Assume you have all sources
in `src` subdirectory and you want all libraries to be sourced from `lib` subdirectory (that is some standard style).
If you using different style, you need to update the example accordingly.

Run this in git root of your project:

```bash
git submodule add https://student.robotika.ceitec.vutbr.cz/VYUKA/BPC-PRP/RoboUtils.git lib/RoboUtils
```

next, add following lines into your CMakeLists ()

```CMake
find_library(libroboutils lib/RoboUtils)

add_subdirectory(lib/RoboUtils)
add_executable(<appname> <... src/main.cpp etc ...>)

target_link_libraries(<appname> PRIVATE libroboutils <... other libs ...>)
```

## Contributors
Ing. Frantisek Burian Ph.D.
with this setup you will have fixed version of library unlike you update it by using ```git pull``` from the ```lib/RoboUtils```
subdirectory. Any future changes to API of the lib will not disturb your project unlike you want to. You will be a god of your code.

## Authors

This library has been originally written by Matous Hybl [[email protected]](mailto:[email protected]) in 2020. We have very thanks for his work.

Some parts has been later reimplemented by Frantisek Burian - bufran _at_ seznam.cz from 2022 for the sake of
demonstrating simple API design, and good programming skills for our BPC-UDP course on Brno university of Technology.



Matous Hybl [[email protected]](mailto:[email protected])
78 changes: 31 additions & 47 deletions include/roboutils/Log.h
Original file line number Diff line number Diff line change
@@ -1,70 +1,54 @@
#include <utility>

#pragma once
//
// Created by Matous Hybl on 2018-10-12.
//

#ifndef FIRMWARE_LOG_H
#define FIRMWARE_LOG_H

#include <utility>
#include <iostream>
#include <string>
#include "roboutils/comm/UDP.h"
#include <functional>
#include <sstream>

#include <roboutils/comm/UDP.h>

namespace RoboUtils {
using namespace std;

class Log {
public:

Log(string level) {
this->level = std::move(level);
}

static Log error();

static Log warning();
private:
const char * level_{nullptr};

static Log info();
class LogLine : public std::stringstream {
public:
explicit LogLine(const Log & parent);
LogLine(LogLine &line);
~LogLine() override;
};

static Log debug();
public:
static const Log error;
static const Log warning;
static const Log info;
static const Log debug;

static void setPath(string path);
static std::function<void(const std::string &)> writer;

static void setRemoteTarget(string address);
explicit constexpr Log(const char *level)
: level_(level)
{
}

template<class T>
Log &operator<<(const T &value) {
buffer << value;

return *this;
LogLine operator<<(const T &value) const {
LogLine line(*this);
line << value;
return line;
}

Log &operator<<(std::ostream &(*manipulator)(std::ostream &)) {
if (manipulator == static_cast<std::ostream &(*)(std::ostream &)>(std::flush) ||
manipulator == static_cast<std::ostream &(*)(std::ostream &)>(std::endl)) {
Log::log(level, buffer.str());

buffer.flush();
}

return *this;
LogLine line() const {
return LogLine(*this);
}

private:
stringstream buffer;
string level;

static string path;
static string address;
static uint16_t port;
static COMM::UDP udp;

static void log(const string& level, const string& message);

static string time();
};
};


#endif //FIRMWARE_LOG_H
}
2 changes: 1 addition & 1 deletion include/roboutils/PIDController.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace RoboUtils {
unsigned int sampleTimeMs = 0;
float absoluteMaximumAction = 0;
};
};
}


#endif //FIRMWARE_PIDCONTROLLER_H
41 changes: 0 additions & 41 deletions include/roboutils/Variable.h

This file was deleted.

32 changes: 20 additions & 12 deletions include/roboutils/chips/ad799x.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,18 +180,26 @@ namespace RoboUtils::Chips::Ad799X {

namespace CONFIG {

// generic for group A, C, D*
#define AD799X_CONFIG_CH(ch) (1 << ((ch)+4))
#define AD799X_CONFIG_CH_ALL (0xFF << 4)
#define AD799X_CONFIG_FLTR (1 << 3)
#define AD799X_CONFIG_ALERTPIN (3 << 1)
#define AD799X_CONFIG_ALERTPIN_DISABLED (0 << 1)
#define AD799X_CONFIG_ALERTPIN_BUSY (1 << 1)
#define AD799X_CONFIG_ALERTPIN_ALERT (2 << 1)
#define AD799X_CONFIG_ALERTPIN_RESET (3 << 1)
#define AD799X_CONFIG_ALERTPOL (1 << 0)
#define AD799X_CONFIG_ALERTPOL_LOW (0 << 0)
#define AD799X_CONFIG_ALERTPOL_HIGH (1 << 0)
static constexpr uint16_t ToCh(int ch) {
return 1 << (ch + 4);
}

// generic for group A, C, D*
enum : uint16_t {
ALERTPOL = 1 << 0,
ALERTBUSY = 1 << 1,
ALERTEN = 1 << 2,
FLTR = 1 << 3,
CH1 = ToCh(0),
CH2 = ToCh(1),
CH3 = ToCh(2),
CH4 = ToCh(3),
CH5 = ToCh(4),
CH6 = ToCh(5),
CH7 = ToCh(6),
CH8 = ToCh(7),
CH = 0xFF << 4,
};

// group B only
#define AD7991_CONFIG_CH(ch) (1 << ((ch)+4))
Expand Down
2 changes: 1 addition & 1 deletion include/roboutils/chips/mcp23017.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ namespace RoboUtils::Chips::Mcp23017 {
};

}
};
}



Loading