Skip to content

Instantly share code, notes, and snippets.

View patrickelectric's full-sized avatar
🏡
Working from home

Patrick José Pereira patrickelectric

🏡
Working from home
View GitHub Profile
@patrickelectric
patrickelectric / ros.md
Created January 29, 2025 17:27
Individual motor control

Individual motor control

ROS

  1. Configure servo\d_function to RC_IN, one for each channel

IQboSywxAiTgRiJeoO55--ixADaCd7ujxmmWNy7KzFo=

@patrickelectric
patrickelectric / ping1d_simple.rs
Created January 29, 2025 11:49
Simple Rust example for Ping1D
use bluerobotics_ping::{device::Ping1D, error::PingError};
use tokio_serial::{SerialPort, SerialPortBuilderExt};
#[tokio::main]
async fn main() -> Result<(), PingError> {
let port = tokio_serial::new("/dev/ttyUSB0", 115200)
.open_native_async()
.map_err(|e| {
eprintln!("Error opening serial port: {}", e);
@patrickelectric
patrickelectric / spi.cpp
Last active December 10, 2024 12:44
Test SPI
#include <iostream>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <linux/gpio.h>
#include <linux/spi/spidev.h>
#include <cstring>
#define GPIO_CHIP_PATH "/dev/gpiochip4"
#define SPI_DEVICE_PATH "/dev/spidev1.0"
@patrickelectric
patrickelectric / example_rust_multiple_traits.rs
Created November 21, 2024 16:46
Multiple trait same object list
use std::error::Error;
pub trait AnyHardware {
fn as_any(&self) -> &dyn std::any::Any;
fn as_any_mut(&mut self) -> &mut dyn std::any::Any;
fn as_accelerometer_sensor(&mut self) -> Option<&mut dyn AccelerometerSensor> {
None
}
fn as_gyroscope_sensor(&mut self) -> Option<&mut dyn GyroscopeSensor> {
@patrickelectric
patrickelectric / zenoh.cpp
Created October 7, 2024 02:24
Speed test with esp32-c3
#include <Arduino.h>
#include <WiFi.h>
#include <zenoh-pico.h>
#define SSID "aaa"
#define PASS "aaa"
// Client mode values
#define MODE "peer" // Change to "peer" or "client" as needed
#define CONNECT "" // If empty, it will scout in 'peer' mode
@patrickelectric
patrickelectric / main.cpp
Last active September 23, 2024 12:35
This is a Zenoh-pico test where my PC and the ESP32S2 waits for each other to publish data and to answer. The ESP32S2 waits for data in `demo/example/topic/0` than receives the values, increment +1, and send it back to the PC via `demo/example/topic/1`. The computer gets the data from `demo/example/topic/1` and publishes it back to `demo/example…
// This code runs in the ESP32S2
#include <Arduino.h>
#include <WiFi.h>
#include <zenoh-pico.h>
#define SSID "ssid"
#define PASS "PASS"
// Client mode values
@patrickelectric
patrickelectric / image_to_udpsink
Created April 3, 2024 13:02
Creates a h264 udpsink from a static image
multifilesrc location="example.jpeg" ! jpegdec ! videoconvert ! imagefreeze ! videobox ! video/x-raw,format=I420,width=240,height=480,framerate=30/1 ! x264enc ! rtph264pay config-interval=1 pt=96 ! udpsink host=192.168.0.55 port=5600
extern crate serde; // 1.0.79
#[macro_use]
extern crate serde_derive; // 1.0.79
extern crate serde_json; // 1.0.30, features = ["raw_value"]
#[derive(Serialize, Deserialize, Debug)]
struct DataBlob<'a> {
id: &'a str,
priority: u8,
payload: &'a serde_json::value::RawValue,
@patrickelectric
patrickelectric / image_processing.qml
Created December 21, 2023 16:14
Do edge filtering in qml
import QtQuick 2.7
import QtQuick.Controls 2.3
Rectangle {
color: "red"
anchors.fill: parent
AnimatedImage {
id: oldFrame
source: "https://cdn.pixabay.com/animation/2022/10/11/09/05/09-05-26-529_512.gif"
@patrickelectric
patrickelectric / main.py
Last active December 11, 2023 11:26
blueos screenshots pages
from selenium import webdriver
from PIL import Image
import time
from imageio import imwrite
url = "http://blueos-avahi.local"
paths = [
'/',
'/vehicle/autopilot',