Skip to content

Instantly share code, notes, and snippets.

View rfzeg's full-sized avatar

Roberto Zegers R. rfzeg

  • The Construct
  • Aachen, Germany
View GitHub Profile
@rfzeg
rfzeg / arm_config.py
Created August 9, 2018 14:04
Forward kinematics for a 2-DoF arm on a plane
import matplotlib.pyplot as plt
import numpy as np
from math import sin, cos
# Define a function to compute the arm configuration
def compute_arm_config(link1_length, link2_length, joint0_angle, joint1_angle):
# compute the (x, y) position of the p1 joint and the end effector at p2.
# input angle in radians
# X0 = distance1 * cos(angle0)
# Y0 = distance1 * sin(angle0)
@rfzeg
rfzeg / angle_conversion_factors.py
Created August 10, 2018 08:40
Reusable conversion factors radians to degrees and degrees to radians
# Conversion Factors
rtd = 180./np.pi # radians to degrees
dtr = np.pi/180. # degrees to radians
@rfzeg
rfzeg / intrinsic_rotation_template.py
Created August 10, 2018 09:57
Perform an intrinsic rotation sequence about the Y and then Z axes
from sympy import symbols, cos, sin, pi, sqrt
from sympy.matrices import Matrix
### Create symbols for joint variables
q1, q2 = symbols('q1:3')
# Create a symbolic matrix representing an intrinsic sequence of rotations
# about the Y and then Z axes. Let the rotation about the Y axis be described
# by q1 and the rotation about Z by q2.
@rfzeg
rfzeg / euler_from_rotation_matrix.py
Created August 10, 2018 13:20
Finds the angles alpha, beta, and gamma, given that numerical values for a rotation matrix are known.
#!/usr/bin/env python
import numpy as np
from sympy.matrices import Matrix
from sympy import symbols, atan2, sqrt
# Conversion Factors
rtd = 180./np.pi # radians to degrees
# Fixed Axis X-Y-Z Rotation Matrix
R_XYZ = Matrix([[ 0.353553390593274, -0.306186217847897, 0.883883476483184],
@rfzeg
rfzeg / homogeneous_transform_matrix .py
Created August 17, 2018 15:08
Individual Homogeneous Transform Matrix
T0_1 = Matrix([[ cos(q1), -sin(q1), 0, a0],
[sin(q1)*cos(alpha0), cos(q1)*cos(alpha0), -sin(alpha0), -sin(alpha0)*d1],
[sin(q1)*sin(alpha0), cos(q1)*sin(alpha0), cos(alpha0), cos(alpha0)*d1],
[ 0, 0, 0, 1]])
@rfzeg
rfzeg / search_list_of_dictionaries.py
Created September 13, 2018 12:08
Function to search list of dictionaries and return a selected value in selected dictionary
# Function to search list of dictionaries and return a selected value in selected dictionary
def search_dictionaries(key1, value1, key2, list_of_dictionaries):
selected_dic = [element for element in list_of_dictionaries if element[key1] == value1][0]
selected_val = selected_dic.get(key2)
return selected_val
@rfzeg
rfzeg / normalize_grayscale.py
Created October 1, 2018 09:56
Normalize a grayscale image with Min-Max scaling to a range of [0.1, 0.9]
def normalize_grayscale(image_data):
"""
Normalize the image data with Min-Max scaling to a range of [0.1, 0.9]
:param image_data: The image data to be normalized
:return: Normalized image data
"""
# Implement Min-Max scaling for grayscale image data
a = 0.1
b = 0.9
grayscale_min = 0
@rfzeg
rfzeg / one_hot_encode.py
Created October 1, 2018 10:34
One hot encode a list of sample labels. Return a one-hot encoded vector for each label.
def one_hot_encode(labels):
"""
One hot encode a list of sample labels. Return a one-hot encoded vector for each label.
: x: List of sample Labels
: return: Numpy array of one-hot encoded labels
"""
# TODO: Implement Function
depth = 10
one_hot = np.eye(depth)[labels]
#!/usr/bin/python
#################################################################
##\file
#
# \note
# Copyright (c) 2010 \n
# Fraunhofer Institute for Manufacturing Engineering
# and Automation (IPA) \n\n
#
#################################################################
@rfzeg
rfzeg / cham_bot.urdf
Created January 24, 2019 10:38
cham-bot
<?xml version="1.0"?>
<robot name="cham_bot">
<link name="z_axis">
<visual>
<geometry>
<box size="0.2 0.2 6.5"/>
</geometry>
<origin rpy="0 0 0" xyz="0.25 0 7"/>