Skip to content
This repository has been archived by the owner on Oct 25, 2023. It is now read-only.

Commit

Permalink
Added current system files from https://github.com/utcoupe/coupe18
Browse files Browse the repository at this point in the history
  • Loading branch information
MadeInPierre committed Sep 23, 2018
0 parents commit b8040a3
Show file tree
Hide file tree
Showing 467 changed files with 30,555 additions and 0 deletions.
54 changes: 54 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
+++++++++### Main git ignore files
### Beware, there are som gitignore files in subdirectories, for local and specific files

# Generated executables
*.elf
*.hex

# Generated CMake associated files
build/
CMakeCache*
CMakeFiles*
cmake_install*

# Generated make associated files
Makefile*

# Generated scons / arduino files
.sconsign.dblite
*find_port

# Generated python files
__pycache__/
*calculate_xy

# Generated npm / node files
node_modules/
npm-debug.log

# IDE specific files
*.sublime*
.idea
.vscode/
cmake-build-debug/

# UTCoupe folders
bin/

# UTCoupe files
tmp.bmp
config.js

# Some other files
*get_distance
*get_distance_intensity
*get_multiecho
*get_multiecho_intensity
*sensor_parameter
*sync_time_stamp
*liburg_c.a
*.swp
.directory

# SymLink to default ROS CMakeLists.txt
ros_ws/src/CMakeLists.txt
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "libs/json"]
path = libs/json
url = https://github.com/nlohmann/json
Binary file added C2018_Rules_final_FR.pdf
Binary file not shown.
674 changes: 674 additions & 0 deletions LICENCE.md

Large diffs are not rendered by default.

84 changes: 84 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
Code source des robots d'UTCoupe 2018
=======

# Configuration

Avant toute chose, il faut cloner le répertoire sur votre ordinateur :
```
git clone [email protected]:utcoupe/coupe18.git
```

### Configurer l'environnement de développement

Un script d'installation automatique est disponible. Allez dans le dossier coupe18, et lancer simplement :
```
./scripts/install_utcoupe_setup.sh
```

Si c'est votre première installation, répondez "y" à toutes les questions.

### Compiler le système

Tout le système de cette année repose sur ROS (http://www.ros.org/), il faut donc compiler le système après l'avoir récupéré et configuré :
```
cd coupe18/ros_ws
catkin_make
```

# Lancement

//TODO

ou must then source the workspace with `source devel/setup.bash` or `source devel/setup.zsh` each
time you open a new terminal. Adding this line to your `~/.bashrc` or `~/.zshrc` (with the full
path to the setup file) will simply automate this step.

# Règles et Guidelines

Afin d'avoir un projet organisé et fonctionnel, voici quelques règles (par convention ou importantes pour le
fonctionnement du projet) à suivre pour la création de branches git, paquets, noeuds ros, etc :

### Git

- Créer des branches sur git de la forme `namespace/package` si la branche correspond à un paquet ROS. (e.g. `ai/scheduler`, `memory/map`, etc)

### Paquets ROS

- Créer des paquets ROS nommés de la forme `namespace_package` (utile une fois qu'ils seront tous ensemble, ils seront ordonnés par
ordre alphabétique : plus visuel)

- Créer des serveurs de `topics`/`services`/`actions` nommés de la forme `/namespace/package/server_name` s'ils peuvent être accédés par des paquets
extérieurs (ATTENTION : avec un `/` au début pour créer un nom absolu), `server_name` s'ils sont internes.

- Nommer les fichiers de définition `.msg`/`.srv`/`.action` en PascalCase (e.g. `GetValues.srv`) et les variables dedans en minuscules (format `var_name`).

### Python

- Afin de respecter le PEP8 : 4 espaces d'intentation (et non tabs).

### Données

- Unités de distance en mètres, transportées par des `float32`.

- Lors de la description d'une position d'une forme (cercle, ligne, rectangle, point...), donner la position par rapport au centre de la forme (sauf précision explicite et nécessaire). Par exemple, donner la position du centre d'un rectangle et non d'un coin.

# Webclient

Pour installer les dépendances du webclient :
```
cd webclient
npm install --only=prod
```

Pour lancer le webclient :
```
npm start
```

S'assurer que le noeud ROS `rosbridge_server` est bien lancé.

Le webclient peut être lancé depuis le robot, ou depuis un ordinateur connecté à la Raspberry.

Si le serveur est lancé sur le robot, se rendre sur `http://<ip_de_la_raspi>:8080`.

Sinon, se rendre sur [http://localhost:8080](http://localhost:8080) et vérifier que le client se connecte bien à l'IP du robot dans les paramètres.
47 changes: 47 additions & 0 deletions arduino/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
cmake_minimum_required(VERSION 2.8)

#todo include it in utcoupe workspace !
set(CMAKE_TOOLCHAIN_FILE $ENV{UTCOUPE_WORKSPACE}/libs/arduino-cmake/cmake/ArduinoToolchain.cmake) # Arduino Toolchain

set(ARDUINO_CXX_FLAGS "${ARDUINO_C_FLAGS} -std=c++11")

# target are : arduino_r_t with r = pr/gr and t = asserv/others
project(arduino C CXX)

set(ARDUINO_DEFAULT_BOARD mega2560)

SET(TARGET_ARDUINO "mega2560" CACHE STRING "User defined arduino target")
SET(TARGET_ROBOT "gr" CACHE STRING "User defined robot")
SET(TARGET_PROGRAM "asserv" CACHE STRING "User defined program")

#todo use the script to determine which port to use
if (TARGET_ARDUINO STREQUAL "nano328")
set(ARDUINO_DEFAULT_PORT /dev/ttyUSB0)
else()
set(ARDUINO_DEFAULT_PORT /dev/ttyACM0)
endif()

SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/../bin)

#set(TARGET_ROBOT gr)
#set(TARGET_PROGRAM asserv)

file(GLOB_RECURSE SRC_FILES ${TARGET_ROBOT}/${TARGET_PROGRAM}/*.cpp ${TARGET_ROBOT}/${TARGET_PROGRAM}/*.c)
include_directories(${TARGET_ROBOT}/${TARGET_PROGRAM} common/${TARGET_PROGRAM} common/shared)

#asserv or others extra common stuff
#set(EXTRA_SRC_FILES "")
file(GLOB_RECURSE EXTRA_SRC_FILES common/${TARGET_PROGRAM}/*.c common/${TARGET_PROGRAM}/*.cpp common/shared/*.cpp)
#if (TARGET_PROGRAM STREQUAL "asserv")
# message("asserv program detected")
# file(GLOB_RECURSE EXTRA_SRC_FILES common/${TARGET_PROGRAM}/*.c common/${TARGET_PROGRAM}/*.cpp)
#endif()

generate_arduino_firmware(${TARGET_ROBOT}_${TARGET_PROGRAM}_${TARGET_ARDUINO}
SRCS ${SRC_FILES} ${EXTRA_SRC_FILES}
# HDRS ${HDR_FILES}
# LIBS HardwareSerial
PORT ${ARDUINO_DEFAULT_PORT}
BOARD ${TARGET_ARDUINO}
)

66 changes: 66 additions & 0 deletions arduino/common/asserv/PID.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/****************************************
* Author : Quentin C *
* Mail : [email protected] *
* Date : 15/04/15 *
****************************************/

#include "parameters.h"
#include "PID.h"
#include "compat.h"

PID_t PID_left, PID_right;

void PIDInit(PID_t *pid) {
pid->P = 0;
pid->I = 0;
pid->D = 0;
pid->bias = 0;
pid->error_sum = 0;
pid->last_error = 0;
pid->init_done = 0;
}

void PIDReset(PID_t *pid) {
pid->error_sum = 0;
pid->last_error = 0;
pid->init_done = 0;
}

void PIDSet(PID_t *pid, float P, float I, float D, float bias) {
I *= PID_I_RATIO;
D *= PID_D_RATIO;
I /= HZ;
D *= HZ;
pid->P = P;
pid->I = I;
pid->D = D;
pid->bias = bias;
PIDReset(pid);
}

float PIDCompute(PID_t *pid, float error) {
float error_D, bias, P_part, I_part, D_part;

if(!pid->init_done){
//Lors du premier compute, on ne tient pas compte de D
error_D = 0;
pid->init_done = 1;
} else {
//derivée = deltaErreur/dt - dt est la période de compute
error_D = (error - pid->last_error);
}

pid->error_sum = (pid->error_sum) + error;
pid->last_error = error;

//calcul de la sortie avec le PID
bias = pid->bias;
P_part = pid->P * error;
I_part = pid->I * pid->error_sum;
if (I_part > PID_I_MAX) I_part = PID_I_MAX;
D_part = pid->D * error_D;
pid->output = bias + P_part + I_part + D_part;
if (pid->output > PID_OUT_MAX) pid->output = PID_OUT_MAX;

return pid->output;
}
23 changes: 23 additions & 0 deletions arduino/common/asserv/PID.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/****************************************
* Author : Quentin C *
* Mail : [email protected] *
* Date : 15/04/15 *
****************************************/
#ifndef PID_H
#define PID_H

typedef struct PID {
float P, I, D, bias;
float error_sum, last_error;
float output;
int init_done;
} PID_t;


extern PID_t PID_left, PID_right;
void PIDInit(PID_t *pid);
void PIDReset(PID_t *pid);
void PIDSet(PID_t *pid, float P, float I, float D, float bias);
float PIDCompute(PID_t *pid, float error);

#endif
106 changes: 106 additions & 0 deletions arduino/common/asserv/asserv.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/****************************************
* Author : Quentin C *
* Mail : [email protected] *
* Date : 13/10/13 *
****************************************/

#include <Arduino.h>
#include "block.h"
#include "compat.h"
#include "parameters.h"
#include "protocol.h"
#include "control.h"
#include "pins.h"
#include "sender.h"
#include <Timer.h>

/**
* Main loop function, check if emergency stop and computes the new command to apply.
* The asserv is working with an internal fifo to execute orders.
* The loop is activate through a Timer (see arduino library).
*/
void asservLoop();
void asservStatus();

// Run the loop for asserv at 100 Hz
Timer asservLoopTimer = Timer(10, &asservLoop);
Timer asservStatusTimer = Timer(100, &asservStatus);

/**
* Read a \n ending string from serial port.
* The timeout is 50ms.
* When a string is received, execute the corresponding order.
*/
void serialRead() {
String receivedString;
if (Serial.available() > 0) {
receivedString = Serial.readStringUntil('\n');
// SerialSender::SerialSend(SERIAL_INFO, receivedString);
receivedString.replace("\n", "");
if (receivedString != "") {
parseAndExecuteOrder(receivedString);
}
}
}

/**
* Arduino setup function, initialize pins and registers.
*/
void setup() {
#ifdef __AVR_ATmega32U4__
Serial.begin(BAUDRATE);
#else
Serial.begin(BAUDRATE, SERIAL_TYPE);
#endif
Serial.setTimeout(5);

#ifdef __AVR_ATmega2560__
TCCR3B = (TCCR3B & 0xF8) | 0x01 ;
TCCR1B = (TCCR1B & 0xF8) | 0x01 ;
#else
#ifdef __AVR_ATmega328P__
TCCR1B = (TCCR1B & 0xF8) | 0x01 ;
#endif
#endif
initPins();
ControlInit();

asservLoopTimer.Start();
asservStatusTimer.Start();
}

/**
* Arduino loop function, read from serial port and send internal serial port data.
* If it is the time to execute asserv, execute it.
*/
void loop() {
if (!flagArduinoConnected) {
SerialSender::SerialSend(SERIAL_INFO, "%s", ARDUINO_ID);
serialRead();
} else {
asservLoopTimer.Update();
asservStatusTimer.Update();
}
SerialSender::SerialSendTask();
if (!flagArduinoConnected) {
delay(1000);
}
}

void asservLoop() {
//Action asserv
ComputeIsBlocked();
ControlCompute();

// That's an ugly way to do it, but not working in another way...
// lastReachedID is defined in control.h file
if(lastReachedID != 0) {
SerialSender::SerialSend(SERIAL_INFO, "%d;", (int)lastReachedID);
lastReachedID = 0;
}
}

void asservStatus() {
serialRead();
ProtocolAutoSendStatus();
}
Loading

0 comments on commit b8040a3

Please sign in to comment.