Skip to content

Commit f8ec713

Browse files
committed
Update docs
1 parent f9ec76c commit f8ec713

1 file changed

Lines changed: 127 additions & 0 deletions

File tree

docs/InstructionsForDevelopers.md

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ Create a folder with the folder name as "exercise_id" at the location from repos
377377
Inside that folder create 2 or more new ones with the following names:
378378

379379
- `<language>_template`: the available languages are `python` and `cpp`. One for each supported language.
380+
- `cpp_lib`: used for precompilation of additional C++ libaries like WebGUI or HAL.
380381
- `frontend`
381382

382383
You may add a teaser to the exercise by creating a file called `teaser.png` using a 9/10 aspect ratio.
@@ -403,8 +404,134 @@ For knowing how to use each package, please follow the links in the list above.
403404

404405
#### Source code: inside `cpp_template`
405406

407+
An exercise must contain this 3 files and a folder:
408+
409+
- **main.cpp**: used as the entrypoint for launching the WebGUI, HAL, console control and the user code. **Must** contain the next code:
410+
411+
```cpp
412+
#include "HAL.hpp"
413+
#include "WebGUI.hpp"
414+
#include "academy.cpp"
415+
#include "rclcpp/rclcpp.hpp"
416+
#include <bits/stdc++.h>
417+
#include <filesystem>
418+
#include <string>
419+
#include <thread>
420+
421+
void start_console()
422+
{
423+
int virtual_terminal = 0;
424+
for (const auto &entry : std::filesystem::directory_iterator("/dev/pts/"))
425+
{
426+
std::filesystem::path outfilename = entry.path();
427+
std::string filename = outfilename.filename().string();
428+
if (filename != "ptmx" && std::stoi(filename) > virtual_terminal)
429+
{
430+
virtual_terminal = std::stoi(filename);
431+
}
432+
}
433+
434+
const std::string v_terminal_str = "/dev/pts/" + std::to_string(virtual_terminal);
435+
436+
if (freopen(v_terminal_str.c_str(), "w", stdout) == NULL)
437+
{
438+
std::cerr << "Error redirecting stdout!" << std::endl;
439+
}
440+
441+
if (freopen(v_terminal_str.c_str(), "w", stderr) == NULL)
442+
{
443+
std::cerr << "Error redirecting stderr!" << std::endl;
444+
}
445+
446+
if (freopen(v_terminal_str.c_str(), "w", stdin) == NULL)
447+
{
448+
std::cerr << "Error redirecting stdin!" << std::endl;
449+
}
450+
};
451+
452+
int main(int argc, char *argv[])
453+
{
454+
rclcpp::init(argc, argv);
455+
start_console();
456+
457+
rclcpp::executors::MultiThreadedExecutor executor(rclcpp::ExecutorOptions(), 2);
458+
459+
auto HAL_node = std::make_shared<HAL>();
460+
executor.add_node(HAL_node);
461+
462+
auto WebGUI_node = std::make_shared<WebGUINode>();
463+
executor.add_node(WebGUI_node);
464+
465+
#ifdef USER_NODE
466+
auto user_node = std::make_shared<UserNode>();
467+
executor.add_node(user_node);
468+
#else
469+
std::thread user(exercise);
470+
#endif
471+
std::thread ros([&executor]{executor.spin();});
472+
WebGUI();
473+
474+
#ifndef USER_NODE
475+
user.join();
476+
#endif
477+
ros.join();
478+
479+
rclcpp::shutdown();
480+
return 0;
481+
}
482+
```
483+
484+
- **package.xml**: Package description of the ROS package.
485+
- **CMakeLists.txt**: needed for compilation of the ROS package.
486+
- **libs/**: needed for storing the libraries for user access.
487+
488+
#### Source code: inside `cpp_lib`
489+
406490
**WORK IN PROGRESS**
407491
492+
This directory contains the source code for the C++ libraries WebGUI, HAL, Frequency and others.
493+
494+
It must contain:
495+
496+
- **src/**: contains the source code for at least HAL, WebGUI and Frequency.
497+
- **include/**: contains the headers for the source code.
498+
- **CMakeLists.txt**: needed for compilation of the libraries.
499+
500+
This directory will not be accesible to the user and will only be used to compile the libraries.
501+
502+
To do that compilation you must launch the **RADI** using Robotics Academy as a **volume** (it is recommende to use the developer script) using the next command (in Linux):
503+
504+
```bash
505+
docker exec -it cf17d87822efd8f7596d8c5dd274ef84789e7be57eaa6a9a78ad7d1e16dd0807 bash
506+
```
507+
508+
Then inside the **RADI** navigate to the desired exercise like:
509+
510+
```bash
511+
cd RoboticsAcademy/exercises/vacuum_cleaner
512+
```
513+
514+
After being inside the exercise directory you must compile the libary inside the **RADI** using;
515+
516+
```bash
517+
cd cpp_lib
518+
mkdir build
519+
cd build/
520+
cmake ..
521+
make
522+
chmod 777 *.so
523+
```
524+
525+
After compiling the libraries you **must** move them to the libs folder created in the **cpp_template** section.
526+
527+
```bash
528+
mv *.so ../../cpp_template/libs/
529+
cd ..
530+
rm -r build/
531+
# Copy the headers to the cpp_template directory
532+
cp -r include/ ../cpp_template/libs/
533+
```
534+
408535
#### Frontend: inside `frontend`
409536

410537
An exercise must contain the following files:

0 commit comments

Comments
 (0)