Skip to content

Instantly share code, notes, and snippets.

View yashi's full-sized avatar

Yasushi SHOJI yashi

View GitHub Profile
@yashi
yashi / CMakeLists.txt
Last active February 21, 2024 02:32
CMakeLists.txt for Python C Extension module
cmake_minimum_required(VERSION 3.20)
project(python_module)
find_package(Python3 COMPONENTS Development.Module)
#Python_add_library(hello MODULE hello.c)
add_library(hello SHARED hello.c)
target_include_directories(hello PRIVATE ${Python_INCLUDE_DIRS})
target_link_libraries(hello Python3::Module)
set_target_properties(hello PROPERTIES PREFIX "")
# When you build ROS by yourself, do NOT have multiple version of
# Python development packages (libpython3.XX-dev).
#
# Because packages in ROS use either
#
# find_package(Python3 REQUIRED COMPONENTS Development)
# or
# find_package(Python3 REQUIRED COMPONENTS Interpreter)
#
# These two give you a different version if you have a different
@yashi
yashi / boost-rolling-mean.cpp
Created January 16, 2024 04:16
Take rolling mean by using boost::accumulators
#include <iostream>
#include <vector>
#include <boost/accumulators/accumulators.hpp>
#include <boost/accumulators/statistics.hpp>
#include <boost/accumulators/statistics/rolling_mean.hpp>
#include <boost/accumulators/statistics/stats.hpp>
namespace ba = boost::accumulators;
int main() {
static int _zbus_message_acc_data_chan = { 42 };
static struct zbus_channel_data _zbus_chan_data_acc_data_chan = {
.observers_start_idx = -1,
.observers_end_idx = -1
};
static struct k_mutex _zbus_mutex_acc_data_chan = {
.wait_q = { { {(&(&_zbus_mutex_acc_data_chan.wait_q)->waitq)}, {(&(&_zbus_mutex_acc_data_chan.wait_q)->waitq)} } },
.owner = NULL,
#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>
#include <zephyr/zbus/zbus.h>
LOG_MODULE_REGISTER(app);
ZBUS_CHAN_DEFINE(acc_data_chan,
int,
NULL,
NULL, /* User data */
ZBUS_OBSERVERS(my_listener, my_subscriber),
static int foo(void)
{
return 42;
}
int main(void)
{
int val = {
foo()
};
&spi4 {
pinctrl-0 = <&spi4_sck_pe2 &spi4_miso_pe5 &spi4_mosi_pe6>;
pinctrl-names = "default";
cs-gpios = <&gpioe 4 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>;
status = "okay";
};
&spi4_sck_pe2 {
bias-pull-up;
};
@yashi
yashi / rpog-cfgmem.tcl
Last active April 26, 2023 12:02
Write .bit to FPGA or .mcs to on-board SPI NOR flash memory
#!/bin/sh
#
# (C) Copyright 2023 Space Cubics, LLC
#
# Make the next line a comment line for TCL \
exec vivado -mode batch -nolog -nojournal -notrace -tempDir $(mktemp -d /tmp/vivado.XXXXXXXXXX) -source "$0" -tclargs ${1+"$@"}
set cfgmem_mode [string match "*cfgmem*" $argv0]
# Set device parameter
$ cat a.c
#include <stdint.h>
uint16_t GetTimer(void);
void delay_us(uint16_t dt) {
uint16_t t1 = GetTimer();
uint16_t t2 = GetTimer() - t1;
while (t2 < dt) {
}
$ gdb -p $(pidof rviz2)
GNU gdb (Debian 12.1-4+b1) 12.1
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see: