Skip to content

Instantly share code, notes, and snippets.

View awesomebytes's full-sized avatar

Sam Pfeiffer awesomebytes

View GitHub Profile
@awesomebytes
awesomebytes / quaternion_from_vectors.py
Created January 22, 2016 09:36
Get a orientation Quaternion from two 3d vectors
def normalize(v):
norm = np.linalg.norm(v)
if norm == 0:
return v
return v / norm
# http://stackoverflow.com/questions/17044296/quaternion-rotation-without-euler-angles
def quaternion_from_vectors(v0, v1):
if type(v0) == Point():
@awesomebytes
awesomebytes / enable_git_shortcuts.bash
Created January 24, 2016 23:47
Script to activate git shortcuts like git co for git checkout
#!/bin/bash
git config --global alias.co checkout
git config --global alias.ci commit
git config --global alias.st status
git config --global alias.br branch
git config --global alias.hist 'log --pretty=format:"%h %ad | %s%d [%an]" --graph --date=short'
git config --global alias.type 'cat-file -t'
git config --global alias.dump 'cat-file -p'
@awesomebytes
awesomebytes / one_line_regexp_python.md
Created January 25, 2016 15:20
One line (kinda long) regular expression substitution in python (for when sed refuses to obey)

One liner python regexp substitution (aka sed-you-should-be-doing-this-properly)

cat only_arm.urdf | python -c "import sys,re;sys.stdout.write(re.sub('<gazebo(.|\n)*?<\/gazebo>*', '', sys.stdin.read()))" > only_arm.urdf.nogazebo 

This was to delete gazebo tags in an URDF file in a single commandline with things that (usually) come with the base system.

@awesomebytes
awesomebytes / pub_imu_steam.py
Created January 26, 2016 00:16
Publishing the imu of the steam controller
#!/usr/bin/env python
"""Publish IMU msg of steam controller"""
from __future__ import division
import sys
from steamcontroller import SteamController
import struct
import rospy
from sensor_msgs.msg import Imu

Deployer says:

Real-time memory: 517920 bytes free of 524288 allocated.
WARNING: You are not root. This program *may* require that you are root.
IOR:010000001f00000049444c3a5254542f636f7262612f435461736b436f6e746578743a312e3000000100000000000000640000000101020
00d0000003139322e3136382e312e3136000033a50e000000fe6580a75600001a12000000000000000200000000000000080000000100000000
545441010000001c00000001000000010001000100000001000105090101000100000009010100
ESC[31m[ERROR] [1453817957.782817839]: Failed to load actuators for transmission 'head_1_trans'.ESC[0m
ESC[31m[ERROR] [1453817958.266321382]: Update cycle took 0.0484193s, which is greater than the control period of 0.
01s.ESC[0m
@awesomebytes
awesomebytes / Malformed_STL_fix.md
Last active January 13, 2025 13:38
How to fix a malformed stl (says Rviz)

Fix malformed stl (says Rviz)

To correct:

The STL file 'package://wsg_50_simulation/meshes/WSG-FMF.stl' is malformed. It starts with the word 'solid', indicating that it's an ASCII STL file, but it does not contain the word 'endsolid' soit is either a malformed ASCII STL file or it is actually a binary STL file. Trying to interpret it as a binary STL file instead.

When launching Rviz with a URDF containing SolidWorks created meshes in STL.

Just go to the folder with STL's with this problem and do:

alias cd..="cd .."
alias ..="cd .."
export PATH="~/bash_tools:$PATH"
# From https://gitlab/pal/pal_scm_utils/blob/master/bash/PAL_aliases.sh
#!/bin/bash
@awesomebytes
awesomebytes / inertia_matrix.py
Last active December 7, 2023 13:39
Compute inertia matrix for simple solids: cube, sphere and cylinder
#/usr/bin/env python
# Based on:
# http://mathworld.wolfram.com/MomentofInertia.html
def get_cube_inertia_matrix(mass, x, y, z):
"""Given mass and dimensions of a cube return intertia matrix.
:return: ixx, ixy, ixz, ixy, iyy, iyz, ixz, iyz, izz
From https://www.wolframalpha.com/input/?i=moment+of+inertia+cube"""
@awesomebytes
awesomebytes / ipython_to_file.md
Created March 16, 2016 10:38
Save iPython session to a python file as code

Save an iPython session commands/code to a file

You must use the magic method %save:

In [1]: %save?
Type:       Magic function
String Form:<bound method CodeMagics.save of <IPython.core.magics.code.CodeMagics object at 0x7fb5d25bb1d0>>
Namespace:  IPython internal
File: /usr/lib/python2.7/dist-packages/IPython/core/magics/code.py
@awesomebytes
awesomebytes / is_simulation_running.py
Created March 20, 2016 20:21
Check if Gazebo simulation is running
#!/usr/bin/env python
from time import sleep
import rospy
if __name__ == '__main__':
rospy.init_node('check_time')
# Until rospy initalizes the time returned will be 0
# so we need to give a bit of time to see if it initializes