Package: basic-robotics
Basic RoboticsBasic Robotics is divided into several different component libraries:basic_robotics.general - Basic robotics math, transforms, helper functionsbasic_robotics.interfaces - Hardware communications skeletons for physical robotsbasic_robotics.kinematics - Serial and Parallel robot kinematics classesbasic_robotics.modern_robotics_numba - Numba enabled version of NxRLab's Modern Roboticsbasic_robotics.path_planning - RRT* path planning variations and spatial indexingbasic_robotics.plotting - Simple Plotting functions for visualizations of robotsbasic_robotics.robot_collisions - Fast Collision Manager for robotics and obstaclesbasic_robotics.utilities - Terminal Displays and LoggingGeneral FunctionalityFASER Interfaces is a general toolkit for functions used elswehere in other related repositories, and feautres tm: a transformation library, FASER: a catchall repository for useful functions, and Faser High Performance, an extension ofModern Robotics's robotics toolkit.FeaturesTM LibraryAbstracted handling and display of transformation matrices.Fully overloaded operators for addition, multiplication, etcGenerate transforms from a variety of input typesEasily extract positions and rotations in a variety of formatsFASER High PerformanceProvides kinematic extensions to the faser_robotics_kinematics libraryAccelerated with Numba, and extendsModern Robotics.FASER (fsr)Catchall functions for manipulation of data elsewhere in FASER systemSimple trajectory generationPosition interpolationUsageUsage Examples:Transformation Libraryimportnumpyasnpfrombasic_robotics.generalimporttm# Import the disp library to properly view instances of the transformationsfrombasic_robotics.utilities.dispimportdisp#The transformation library allows for seamless usage of rotation matrices and other forms of rotation information encoding.identity_matrix=tm()disp(identity_matrix,'identity')#This is just zeros in TAA format.#Let's create a few more.trans_x_2m=tm([2,0,0,0,0,0])#Translations can be created with a list (Xm, Ym, Zm, Xrad, Yrad, Zrad)trans_y_4m=tm(np.array([0,4,0,0,0,0]))# Translations can be created with a numpy arrayrot_z_90=tm([0,0,0,0,0,np.pi/2])# Rotations can be declared in radianstrans_z_2m_neg=tm(np.array([[1,0,0,0],[0,1,0,0],[0,0,1,-2],[0,0,0,1]]))# Transformations can be created from rotation matricestrans_x_2m_quat=tm([2,0,0,0,0,0,1])# Transformations can even be declared with quaternionslist_of_transforms=[trans_x_2m,trans_y_4m,rot_z_90]disp(list_of_transforms,'transform list')# List of transforms will be displayed in columns#Operationsnew_simple_transform=trans_x_2m+trans_y_4m#Additon is element-wise on TAA formnew_transform_multiplied=trans_x_2m@trans_y_4m#Transformation matrix multiplication uses '@'new_double_transform=trans_x_2m*2# Multiplication by a scalar is elementwise#And more visible in the function list documentation#And more visible in the function list documentationDetailed Usage TODOInterfacesFASER Interfaces is a simple toolkit for communicating over serial and udp through a common interface, and used generally to communicate with robots or sensorsFeaturesGeneralized "Comms" implementationCommunications supervisorStandard interface for Serial and UDPUsageDetailed Usage TODOKinematicsFASER Robotics Kinematics is a toolbox for kinematics, statics, and dynamics of Stewart Platforms and Serial Manipulators, largely based onModern Robotics. It is part of a set of related robotics repositories hosted here.FeaturesStewart Platforms:Forward and Inverse KinematicsStatic Analysis and Force CalculationsCustom ConfigurationsError detection and correctionSerial Manipulators:Forward and Inverse KinematicsStatic Analysis and Force CalculationsCustom ConfigurationsError detection and correctionDynamics AnalysisVisual Servoing and Path PlanningUsageDetailed Usage TODOStewart Platform Exampleimportjsonimportosimportmatplotlib.pyplotaspltimportbasic_robotics#Import the General Libraryfrombasic_robotics.generalimporttm#Import transformation libraryfrombasic_robotics.utilities.dispimportdisp# SP Testsdisp("Beginning SP Test")frombasic_robotics.kinematicsimportloadSPfrombasic_robotics.plotting.vis_matplotlibimportDrawSPbasic_sp={"Name":"Basic SP","Type":"SP","BottomPlate":{"Thickness":0.1,"JointRadius":0.9,"JointSpacing":9,"Mass":6},"TopPlate":{"Thickness":0.16,"JointRadius":0.3,"JointSpacing":25,"Mass":1},"Actuators":{"MinExtension":0.75,"MaxExtension":1.5,"MotorMass":0.5,"ShaftMass":0.9,"ForceLimit":800,"MotorCOGD":0.2,"ShaftCOGD":0.2},"Drawing":{"TopRadius":1,"BottomRadius":1,"ShaftRadius":0.1,"MotorRadius":0.2},"Settings":{"MaxAngleDev":55,"GenerateActuators":0,"IgnoreRestHeight":1,"UseSpin":0,"AssignMasses":1,"InferActuatorCOG":1},"Params":{"RestHeight":1.2,"Spin":30}}basic_sp_string=json.dumps(basic_sp)withopen('sp_test_data.json','w')asoutfile:outfile.write(basic_sp_string)sp_model=loadSP('sp_test_data.json','')fig=plt.figure()ax=plt.axes(projection='3d')ax.set_xlim3d(-1,1)ax.set_ylim3d(-1,1)ax.set_zlim3d(0,2)#Delete fileos.remove('sp_test_data.json')DrawSP(sp_model,ax)plt.show()Loading an Arm The Easy Wayfrombasic_robotics.kinematicsimportloadArmFromURDF#Load the Armnew_arm=loadArmFromURDF('some_example_robot.urdf')#You're Done!Loading an Arm The Hard Wayfrombasic_robotics.generalimporttm,fsrfrombasic_robotics.kinematicsimportArmfrombasic_robotics.plotting.vis_matplotlibimport*fig=plt.figure()ax=plt.axes(projection='3d')ax.set_xlim3d(-3,3)ax.set_ylim3d(-3,3)ax.set_zlim3d(0,6)Base_T=tm()# Set a transformation for the base# Define some link lengthsL1=3L2=3L3=3W=0.1# Define the transformations of each linkTspace=[tm(np.array([[0],[0],[L1/2],[0],[0],[0]])),tm(np.array([[L2/2],[0],[L1],[0],[0],[0]])),tm(np.array([[L2+(L3/2)],[0],[L1],[0],[0],[0]])),tm(np.array([[L2+L3+(W/2)],[0],[L1],[0],[0],[0]])),tm(np.array([[L2+L3+W+(W/2)],[0],[L1],[0],[0],[0]])),tm(np.array([[L2+L3+W+W+(W/2)],[0],[L1],[0],[0],[0]]))]basic_arm_end_effector_home=fsr.TAAtoTM(np.array([[L2+L3+W+W+W],[0],[L1],[0],[0],[0]]))basic_arm_joint_axes=np.array([[0,0,1],[0,1,0],[0,1,0],[1,0,0],[0,1,0],[1,0,0]]).conj().Tbasic_arm_joint_homes=np.array([[0,0,0],[0,0,L1],[L2,0,L1],[L2+L3,0,L1],[L2+L3+W,0,L1],[L2+L3+2*W,0,L1]]).conj().Tbasic_arm_screw_list=np.zeros((6,6))#Create the screw listforiinrange(0,6):basic_arm_screw_list[0:6,i]=np.hstack((basic_arm_joint_axes[0:3,i],np.cross(basic_arm_joint_homes[0:3,i],basic_arm_joint_axes[0:3,i])))#Input some basic dimensionsbasic_arm_link_box_dims=np.array([[W,W,L1],[L2,W,W],[L3,W,W],[W,W,W],[W,W,W],[W,W,W]]).conj().Tbasic_arm_link_mass_transforms=[None]*(len(basic_arm_screw_list)+1)basic_arm_link_mass_transforms[0]=Tspace[0]#Set mass transformsforiinrange(1,6):basic_arm_link_mass_transforms[i]=(Tspace[i-1].inv()@Tspace[i])basic_arm_link_mass_transforms[6]=(Tspace[5].inv()@basic_arm_end_effector_home)masses=np.array([20,20,20,1,1,1])basic_arm_inertia_list=np.zeros((6,6,6))#Create spatial inertia matrices for linksforiinrange(6):basic_arm_inertia_list[i,:,:]=fsr.boxSpatialInertia(masses[i],basic_arm_link_box_dims[0,i],basic_arm_link_box_dims[1,i],basic_arm_link_box_dims[2,i])# Create the arm from the above paramtersarm=Arm(Base_T,basic_arm_screw_list,basic_arm_end_effector_home,basic_arm_joint_homes,basic_arm_joint_axes)#ALTERNATIVELY, JUST LOAD A URDF USING THE 'loadArmFromURDF' function in basic_robotics.kinematicsarm.setDynamicsProperties(basic_arm_link_mass_transforms,Tspace,basic_arm_inertia_list,basic_arm_link_box_dims)arm.joint_mins=np.array([np.pi,np.pi,np.pi,np.pi,np.pi,np.pi])*-2arm.joint_maxs=np.array([np.pi,np.pi,np.pi,np.pi,np.pi,np.pi])*2#Draw the arm at a couple positions#DrawArm(arm, ax, jdia = .3)goal=arm.FK(np.array([np.pi/2,np.pi/4,-np.pi/4+.1,0,0,0]))DrawArm(arm,ax,jdia=.3)plt.show()Modern Robotics - NumbaTODO Explanation
This repository contains the code library accompanyingModern Robotics:
Mechanics, Planning, and Control(Kevin Lynch
and Frank Park, Cambridge University Press 2017). Theuser manualis in the doc directory.The functions are available in:PythonMATLABMathematicaEach function has a commented section above it explaining the inputs required for its use as well as an example of how it can be used and what the output will be. This repository also contains a pdf document that provides an overview of the available functions using MATLAB syntax. Functions are organized according to the chapter in which they are introduced in the book. Basic functions, such as functions to calculate the magnitude of a vector, normalize a vector, test if the value is near zero, and perform matrix operations such as multiplication and inverses, are not documented here.The primary purpose of the provided software is to be easy to read and educational, reinforcing the concepts in the book. The code is optimized neither for efficiency nor robustness.Path PlanningFASER Path planning is a toolbox for using RRT* to plan paths quickly through adverse terrain in a generalized sense (compatible with a wide variety of robotic tools)FeaturesRRT* generation for various configurationsFake terrain generationCollision detection and obstacle avoidanceBindable functions for advanced tuningDual Path RRT* for quicker solution findingUsageSimple Path Generationfrombasic_robotics.kinematicsimportloadArmFromURDFfrombasic_robotics.path_planningimportRRTStar,PathNodefrombasic_robotics.plotting.vis_matplotlibimport*fig=plt.figure()ax=plt.axes(projection='3d')ax.set_xlim3d(-1,1)ax.set_ylim3d(-1,1)ax.set_zlim3d(0,2)arm=loadArmFromURDF('tests/test_helpers/irb_2400.urdf')#Generate an RRT* instanceinit=arm.getEEPos()rrt=RRTStar(init)rrt.addObstruction([0.5,0.5,0.7],[1.2,1.2,1.2])# Add some random obstructionsrrt.addObstruction([0.5,0.5,-2],[1,1,0.5])DrawArm(arm,ax)goal=arm.FK(np.array([np.pi/3,np.pi/3,-np.pi/8,np.pi/10,-np.pi/4,np.pi/5]))arm.FK(np.zeros(6))DrawObstructions(rrt.obstructions,ax)#Draw the obstructions for visulization#Find a path through the environmentrandom.seed(10)traj=rrt.findPathGeneral(lambda:rrt.generalGenerateTree(# Generate a general RRT* tree using:lambda:PathNode(arm.randomPos()),# Random generation for path nodeslambdax,y:rrt.distance(x,y),# Distance between nodes as a costlambdax,y:rrt.armObstruction(arm,x,y)),#Basic rtree collision detection as obstruction checkinggoal)# Goal positionDrawRRTPath(traj,ax,'green')# Draw the finalized pathplt.show()#Show the plotDetailed Usage TODOPlottingFASER Plotting is a simple toolbox which extends matplotlib to draw simple shapes and show how a robot fits together.FeaturesAnimate videos using matplotlib framesPlot various primary shapesPlot FASER RobotsPlot transforms and wrenchesUsageDetailed Usage TODORobot CollisionsProvides support for detecting collisions between Robot objects and user supplied obstacles, or other robots. Supports both creation of basic shapes, and loading in robot geometry (from URDFs for example)Usagefrombasic_robotics.kinematicsimportloadArmFromURDFfrombasic_robotics.collisionsimportColliderManager,ColliderObject,ColliderArm,createMesharm1=loadArmFromURDF('some_arm.urdf')arm2=loadArmFromURDF('another_arm.urdf')manager=ColliderManager()arm1_collider=ColliderArm(arm1,'arm1')arm2_collider=ColliderArm(arm2,'arm2')arm1_collider.bindManager(manager)arm2_collider.bindManager(manager)print(manager.checkCollisions())random_mesh_series=ColliderObject()random_mesh_series.bindManager(manager)random_mesh_series.addMesh('mesh_1',createMesh('first_mesh.stl',tm()))random_mesh_series.addMesh('mesh_2',createMesh('second_mesh.stl',tm()))print(manager.checkCollisions())UtilitiesUtilities contains display and logging tools generally useful for working with other components in this packageFeaturesmatlab like display function 'disp' which is a drop in replacement for python print()JSON file logging toolPrint matrices with appropriate labelsProgressBar displayUsageDetailed Usage TODOContributingPull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.LicenseMIT