Skip to content

Instantly share code, notes, and snippets.

@surajRathi
surajRathi / line_segment.py
Created January 16, 2022 05:57
Helper class for dealing with points and line segments
import numpy as np
# https://www.desmos.com/calculator/acagoky1yo
Point2 = np.ndarray # np.ndarray[2,]
def dist(p1: Point2, p2: Point2):
return np.linalg.norm(p2 - p1)
class LineSegment:
@surajRathi
surajRathi / rosremote
Created February 13, 2022 10:03
rosremote: Shell Script to setup variables to use rosmaster on the ssh client
#! /usr/bin/zsh
source /opt/ros/noetic/setup.zsh
export ROS_MASTER_URI="http://$(echo $SSH_CLIENT | cut -d ' ' -f 1):11311"
export ROS_HOSTNAME="$(hostname -I | cut -d ' ' -f 1)"
$@
@surajRathi
surajRathi / subscribe_camera.cpp
Created February 21, 2022 10:28
Use image_transport::subscribe_camera
#include <ros/ros.h>
#include <image_transport/image_transport.h>
int main(int argc, char *argv[]) {
ros::init(argc, argv, "auto_brightness", ros::init_options::AnonymousName);
ros::NodeHandle nh, pnh("~");
image_transport::ImageTransport it{nh}; // Is this necessary?
@surajRathi
surajRathi / rankmirrors.sh
Created February 27, 2022 18:56
Arch Linux rankmirrors
#!/usr/bin/sh
sed 's:#Server:Server:' /etc/pacman.d/mirrorlist.pacnew | grep -Ev "^#|^$" | rankmirrors - -n 10 | sudo tee /etc/pacman.d/mirrorlist && sudo rm /etc/pacman.d/mirrorlist.pacnew
@surajRathi
surajRathi / install.sh
Created March 7, 2022 11:49
rosdep install dependencies for a custom package
#! /usr/bin/sh
rosdep install -yr --ignore-src --from-paths ./
@surajRathi
surajRathi / cc_setup.zsh
Created March 22, 2022 07:12
Integrate clion with multi package catkin tools setup
export ROS_HOSTNAME=$(hostname -I | awk '{print $1}' | head -c -1 -)
source ./devel/setup.zsh
export CATKIN_PROFILE="$(catkin profile list | awk '/\(active\)/{print $2}')"
echo -ne "[\n]" > $ROS_WS_DIR/.catkin_tools/CATKIN_BUILD_DUMMY.json
catkin_build() {
catkin build $@
@surajRathi
surajRathi / serial_tunnel.sh
Created April 20, 2022 13:35
USB Serial over ssh
#! /usr/bin/zsh
socat PTY,link=$HOME/myserialline,raw,echo=0 EXEC:'ssh suraj@rathi socat - /dev/ttyACM0'
#! /usr/bin/python3
import time
from math import pi
from typing import List, Optional, Tuple
import serial
# Received garbage
class InvalidResponse(Exception):
import os
import select
import sys
import time
if os.name == 'nt':
import msvcrt
else:
import tty
@surajRathi
surajRathi / ros_costmap_subscriber.py
Created July 12, 2022 12:54
Subscribes to the ROS 'costmap', i.e. `nav_msgs/OccupancyGrid` and the linked `map_msgs/OccupancyGridUpdate`
#! /usr/bin/python3
from typing import Optional
import numpy as np
import rospy
from map_msgs.msg import OccupancyGridUpdate
from nav_msgs.msg import OccupancyGrid
from rospy.numpy_msg import numpy_msg