Skip to content
Snippets Groups Projects
Commit 40ad8d3c authored by Paul LE GAL LA SALLE's avatar Paul LE GAL LA SALLE
Browse files

init

parent 81bb5875
No related branches found
No related tags found
No related merge requests found
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch
This directory is intended for project header files.
A header file is a file containing C declarations and macro definitions
to be shared between several project source files. You request the use of a
header file in your project source file (C, C++, etc) located in `src` folder
by including it, with the C preprocessing directive `#include'.
```src/main.c
#include "header.h"
int main (void)
{
...
}
```
Including a header file produces the same results as copying the header file
into each source file that needs it. Such copying would be time-consuming
and error-prone. With a header file, the related declarations appear
in only one place. If they need to be changed, they can be changed in one
place, and programs that include the header file will automatically use the
new version when next recompiled. The header file eliminates the labor of
finding and changing all the copies as well as the risk that a failure to
find one copy will result in inconsistencies within a program.
In C, the usual convention is to give header files names that end with `.h'.
It is most portable to use only letters, digits, dashes, and underscores in
header file names, and at most one dot.
Read more about using header files in official GCC documentation:
* Include Syntax
* Include Operation
* Once-Only Headers
* Computed Includes
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
#ifndef PINS_HPP
#define PINS_HPP
#define BUTTON_LEFT 2
#define BUTTON_MIDDLE 3
#define BUTTON_RIGHT 10
#define TIRETTE 16
#define LED_PIN 25
#endif
\ No newline at end of file
This directory is intended for project specific (private) libraries.
PlatformIO will compile them to static libraries and link into executable file.
The source code of each library should be placed in a an own separate directory
("lib/your_library_name/[here are source files]").
For example, see a structure of the following two libraries `Foo` and `Bar`:
|--lib
| |
| |--Bar
| | |--docs
| | |--examples
| | |--src
| | |- Bar.c
| | |- Bar.h
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
| |
| |--Foo
| | |- Foo.c
| | |- Foo.h
| |
| |- README --> THIS FILE
|
|- platformio.ini
|--src
|- main.c
and a contents of `src/main.c`:
```
#include <Foo.h>
#include <Bar.h>
int main (void)
{
...
}
```
PlatformIO Library Dependency Finder will find automatically dependent
libraries scanning project source files.
More information about PlatformIO Library Dependency Finder
- https://docs.platformio.org/page/librarymanager/ldf.html
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
;[env:esp32]
;platform = espressif32
;board = esp32dev
;framework = arduino
;lib_deps =
; https://github.com/micro-ROS/micro_ros_platformio
;board_microros_distro = foxy
;board_microros_transport = serial
[env:pico]
platform = raspberrypi
board = pico
framework = arduino
lib_deps =
https://github.com/micro-ROS/micro_ros_platformio
board_microros_distro = foxy
board_microros_transport = serial
upload_protocol = picotool
upload_port = /dev/ttyACM0
monitor_speed = 115200
\ No newline at end of file
#include <Arduino.h>
#include <micro_ros_platformio.h>
#include "pins.hpp"
#include <rcl/rcl.h>
#include <rclc/rclc.h>
#include <rclc/executor.h>
#include <std_msgs/msg/int32.h>
#if !defined(MICRO_ROS_TRANSPORT_ARDUINO_SERIAL)
#error This example is only avaliable for Arduino framework with serial transport.
#endif
//rcl_subscription_t subscriber;
rcl_publisher_t button_left_publisher;
rcl_publisher_t button_middle_publisher;
rcl_publisher_t button_right_publisher;
rcl_publisher_t tirette_publisher;
std_msgs__msg__Int32 msg;
rclc_executor_t executor;
rclc_support_t support;
rcl_allocator_t allocator;
rcl_node_t node;
rcl_timer_t timer;
#define RCCHECK(fn) { rcl_ret_t temp_rc = fn; if((temp_rc != RCL_RET_OK)){error_loop();}}
#define RCSOFTCHECK(fn) { rcl_ret_t temp_rc = fn; if((temp_rc != RCL_RET_OK)){}}
// Error handle loop
void error_loop() {
while(1) {
delay(100);
}
}
int mult = 0;
void timer_callback(rcl_timer_t * timer, int64_t last_call_time) {
msg.data = !digitalRead(BUTTON_LEFT);
RCSOFTCHECK(rcl_publish(&button_left_publisher, &msg, NULL));
msg.data = !digitalRead(BUTTON_MIDDLE);
RCSOFTCHECK(rcl_publish(&button_middle_publisher, &msg, NULL));
msg.data = !digitalRead(BUTTON_RIGHT);
RCSOFTCHECK(rcl_publish(&button_right_publisher, &msg, NULL));
msg.data = !digitalRead(TIRETTE);
RCSOFTCHECK(rcl_publish(&tirette_publisher, &msg, NULL));
}
void setup() {
// Configure serial transport
Serial.begin(115200);
set_microros_serial_transports(Serial);
delay(2000);
pinMode(BUTTON_LEFT, INPUT_PULLUP);
pinMode(BUTTON_MIDDLE, INPUT_PULLUP);
pinMode(BUTTON_RIGHT, INPUT_PULLUP);
pinMode(TIRETTE, INPUT_PULLUP);
allocator = rcl_get_default_allocator();
//create init_options
RCCHECK(rclc_support_init(&support, 0, NULL, &allocator));
// create node
RCCHECK(rclc_node_init_default(&node, "ctrl_panel_ucontroller", "", &support));
RCCHECK(rclc_publisher_init_default(
&button_left_publisher,
&node,
ROSIDL_GET_MSG_TYPE_SUPPORT(std_msgs, msg, Int32),
"ctrl_panel/left_button"));
RCCHECK(rclc_publisher_init_default(
&button_middle_publisher,
&node,
ROSIDL_GET_MSG_TYPE_SUPPORT(std_msgs, msg, Int32),
"ctrl_panel/middle_button"));
RCCHECK(rclc_publisher_init_default(
&button_right_publisher,
&node,
ROSIDL_GET_MSG_TYPE_SUPPORT(std_msgs, msg, Int32),
"ctrl_panel/right_button"));
RCCHECK(rclc_publisher_init_default(
&tirette_publisher,
&node,
ROSIDL_GET_MSG_TYPE_SUPPORT(std_msgs, msg, Int32),
"ctrl_panel/tirette"));
const unsigned int timer_timeout = 10;
RCCHECK(rclc_timer_init_default(
&timer,
&support,
RCL_MS_TO_NS(timer_timeout),
timer_callback));
// create executor
RCCHECK(rclc_executor_init(&executor, &support.context, 2, &allocator));
RCCHECK(rclc_executor_add_timer(&executor, &timer));
//RCCHECK(rclc_executor_add_subscription(&executor, &subscriber, &msg, &subscription_callback, ON_NEW_DATA));
msg.data = 0;
}
void loop() {
RCSOFTCHECK(rclc_executor_spin_some(&executor, RCL_US_TO_NS(1000)));
}
\ No newline at end of file
This directory is intended for PlatformIO Test Runner and project tests.
Unit Testing is a software testing method by which individual units of
source code, sets of one or more MCU program modules together with associated
control data, usage procedures, and operating procedures, are tested to
determine whether they are fit for use. Unit testing finds problems early
in the development cycle.
More information about PlatformIO Unit Testing:
- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment