Skip to content

Instantly share code, notes, and snippets.

View akihikoy's full-sized avatar

akihikoy akihikoy

View GitHub Profile
from html.parser import HTMLParser
import re
class MyHTMLParser(HTMLParser):
def __init__(self):
HTMLParser.__init__(self)
self.mode= None
self.serialized= []
def handle_starttag(self, tag, attrs):
@akihikoy
akihikoy / current_pos2.py
Created January 22, 2019 11:47
Reading servo positions from two Dynamixels.
#!/usr/bin/python
#Printing current position without enabling torque.
from dxl_util import *
from _config import *
import time
#Setup the device
DXL_ID= [1,2] #IDs of the Dynamixels.
BAUDRATE= 57600
@akihikoy
akihikoy / ch_id.py
Created January 22, 2019 11:43
Change ID of Dynamixel
#!/usr/bin/python
#Change ID.
from dxl_util import *
DXL_ID= 1 #Current ID
NEW_ID= 2 #New ID
BAUDRATE= 57600
#DXL_TYPE= 'XM430-W350' #Finger robot
DXL_TYPE= 'XH430-V350' #Dynamixel gripper
// Changing exposure worked with the ELP camera on Windows.
#include "stdafx.h"
#include <opencv2/opencv.hpp>
bool ParamChanged(false);
void OnTrack(int,void*)
{
ParamChanged= true;
}
#!/usr/bin/python
from core_tool import *
import cv2
import numpy as np
def Run(ct,*arg):
cap = cv2.VideoCapture('http://aypi11:8081/?action=stream&dummy=file.mjpg')
#q0= np.array(ct.robot.Q())
t0= rospy.Time.now()
@akihikoy
akihikoy / first.py
Created August 14, 2018 06:44
Step by step ay_trick SCRIPT tutorial
#!/usr/bin/python
from core_tool import *
def Help():
return '''First script.
Usage: a.ros'''
def Run(ct,*args):
print len(args)
print args[0]
q= list(ct.robot.Q())
'''
Following codes are an example of processing marker tracker topic from FingerVision.
I just copied them from my system, which might be incomplete, but you could find the idea of the calculation.
The main function to process the marker tracker topic is BlobMoves.
(see `def BlobMoves(t,l,msg,side)`)
t: Interface of core tools (ROS connection, robot controller, etc.); you can replace t by adequate functions.
l: A container object. The simplest implementation is like:
class Container(): pass
l= Container()
@akihikoy
akihikoy / Dynamixel-XM430-read_write.py
Created March 25, 2017 23:54
Controlling Dynamixel XM430 through USB2Dynamixel. This code is based on DynamixelSDK/python/protocol2_0/sync_read_write.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
################################################################################
# Copyright (c) 2016, ROBOTIS CO., LTD.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
#!/usr/bin/python
#NOTE: Remove and Upgrade scikit-learn (v.1.8 is necessary)
# sudo apt-get remove python-sklearn python-sklearn-lib
# sudo pip install -U scikit-learn
import random, math
import numpy as np
import matplotlib.pyplot as plot
from mpl_toolkits.mplot3d import Axes3D
from sklearn.gaussian_process import GaussianProcessRegressor
#!/usr/bin/python
#Download CMA-ES for Python from https://www.lri.fr/~hansen/cmaesintro.html
#and put cma.py in the same directory
import numpy as np
import matplotlib.pyplot as plot
from fk import FK
import cma
plot.ioff() #cma set matplotlib.pyplot.ion()
#Error function of inverse kinematics