Package: rvc3python
Robotics, Vision & Control: 3rd edition in Python (2023)Welcome to the online hub for the book:Robotics, Vision & Control: fundamental algorithms in Python (3rd edition)Peter Corke, published by Springer-Nature 2023.ISBN978-3-031-06468-5 (hardcopy), 978-3-031-06469-2 (eBook)DOI10.1007/978-3-031-06469-2Report an issue with the book or its supporting codehere.Knwon errata for the book can be viewedhere.This book uses many examples based on the following open-source Python packagesRobotics Toolbox for Python,Machine Vision Toolbox for Python,Spatial Maths Toolbox for Python,Block Diagram Simulation for Python.  These in turn have dependencies on other packages created by the author and
third parties.Installing the packageThis package provides a simple one-step installation ofallthe required Toolboxespipinstallrvc3pythonorcondainstallrvc3pythonThere are a lot of dependencies and this might take a minute or so.  You now have a very
powerful computing environment for robotics and computer vision.Python versionGiven the rapid rate of language additions, particularly around type hinting, use at
least Python 3.8.  Python 3.7 goes end of life in June 2023.Not all package dependencies will work with the latest release of Python.  In particular, check:PyTorchused for segmentation examples in Chapter 12Open3D, used for point cloud examples in Chapter 14.Installing into a Conda environmentIt's probably a good idea to create a virtual environment to keep this package
and its dependencies separated from your other Python code and projects.  If you've
never used virtual environments before this might be a good time to start, and it
is really easyusing Conda:condacreate-nRVC3python=3.10
condaactivateRVC3
pipinstallrvc3pythonInstalling deep learning toolsChapter 11 has some deep learning examples based on PyTorch.  If you don't have
PyTorch installed you can use thepytorchinstall optionpipinstallrvc3python[pytorch]orcondainstallrvc3python[pytorch]Using the ToolboxesThe simplest way to get going is to use the command line tool$rvctool___________________________|_\___||_____||_(_)______\ \/(_)___(_)______(_)/___|______||_______|||___/||_)/_\|'_ \ / _ \| __| |/ __/ __|    \ \ / /| / __| |/ _ \| '_\/_\/\||/_\|'_ \| __| '__/_\|||_\|_<(_)||_)|(_)||_||(__\__\_\V/|\__\|(_)|||||(_><||__|(_)|||||_|||(_)||___)||_|\_\___/|_.__/\___/\__|_|\___|___()\_/|_|___/_|\___/|_||_|\___/\/\____\___/|_||_|\__|_|\___/|_||____/|/forPython(RTB==1.1.0,MVTB==0.9.5,SG==1.1.7,SMTB==1.1.7,NumPy==1.24.2,SciPy==1.10.1,Matplotlib==3.7.1)importmathimportnumpyasnpfromscipyimportlinalg,optimizeimportmatplotlib.pyplotaspltfromspatialmathimport*fromspatialmath.baseimport*fromspatialmath.baseimportsymfromspatialgeometryimport*fromroboticstoolboximport*frommachinevisiontoolboximport*importmachinevisiontoolbox.baseasmvb# useful variablesfrommathimportpipuma=models.DH.Puma560()panda=models.DH.Panda()func/object?-showbriefhelphelp(func/object)-showdetailedhelpfunc/object??-showsourcecode

Resultsofassignmentswillbedisplayed,usetrailing;tosuppressPython3.10.9|packagedbyconda-forge|(main,Feb22023,20:24:27)[Clang14.0.6]Type'copyright','credits'or'license'formoreinformation
IPython8.11.0--AnenhancedInteractivePython.Type'?'forhelp.


>>>This provides an interactive Python
(IPython) session with all the Toolboxes and
supporting packages imported, and ready to go.  It's a highly capable, convenient, and
"MATLAB-like" workbench environment for robotics and computer vision.For example to load an ETS model of a Panda robot, solve a forward kinematics
and inverse kinematics problem, and an interactive graphical display is simply:>>>panda=models.ETS.Panda()ERobot:Panda(byFrankaEmika),7joints(RRRRRRR)┌─────┬───────┬───────┬────────┬─────────────────────────────────────────────┐│link│link│joint│parent│ETS:parenttolink│├─────┼───────┼───────┼────────┼─────────────────────────────────────────────┤│0│link0│0│BASE│tz(0.333)⊕Rz(q0)││1│link1│1│link0│Rx(-90°)⊕Rz(q1)││2│link2│2│link1│Rx(90°)⊕tz(0.316)⊕Rz(q2)││3│link3│3│link2│tx(0.0825)⊕Rx(90°)⊕Rz(q3)││4│link4│4│link3│tx(-0.0825)⊕Rx(-90°)⊕tz(0.384)⊕Rz(q4)││5│link5│5│link4│Rx(90°)⊕Rz(q5)││6│link6│6│link5│tx(0.088)⊕Rx(90°)⊕tz(0.107)⊕Rz(q6)││7│@ee││link6│tz(0.103)⊕Rz(-45°)│└─────┴───────┴───────┴────────┴─────────────────────────────────────────────┘┌─────┬─────┬────────┬─────┬───────┬─────┬───────┬──────┐│name│q0│q1│q2│q3│q4│q5│q6│├─────┼─────┼────────┼─────┼───────┼─────┼───────┼──────┤│qr│0°│-17.2°│0°│-126°│0°│115°│45°││qz│0°│0°│0°│0°│0°│0°│0°│└─────┴─────┴────────┴─────┴───────┴─────┴───────┴──────┘>>>panda.fkine(panda.qz)0.70710.707100.0880.7071-0.70710000-10.8230001>>>panda.ikine_LM(SE3.Trans(0.4,0.5,0.2)*SE3.Ry(pi/2))IKSolution(q=array([-1.849,-2.576,-2.914,1.22,-1.587,2.056,-1.013]),success=True,iterations=13,searches=1,residual=3.3549072615799585e-10,reason='Success')>>>panda.teach(panda.qz)Computer vision is just as easy.  For example, we can import an image, blur it
and display it alongside the original>>>mona=Image.Read("monalisa.png")>>>Image.Hstack([mona,mona.smooth(sigma=5)]).disp()or load two images of the same scene, compute SIFT features and display putative
matches>>>sf1=Image.Read("eiffel-1.png",mono=True).SIFT()>>>sf2=Image.Read("eiffel-2.png",mono=True).SIFT()>>>matches=sf1.match(sf2)>>>matches.subset(100).plot("w")rvctoolis a wrapper aroundIPythonwhere:robotics and vision functions and classes can be accessed without needing
package prefixesresults are displayed by default like MATLAB does, and like MATLAB you need to
put a semicolon on the end of the line to prevent thisthe prompt is the standard Python REPL prompt>>>rather than the IPython
prompt, this can be overridden by a command-line switchallows cutting and pasting in lines from the book, and prompt characters are
ignoredThe Robotics, Vision & Control book usesrvctoolfor all the included
examples.rvctoolimports the all the above mentioned packages usingimport *which is
not considered best Python practice.  It is very convenient for interactive
experimentation, but in your own code you can handle the imports as you see
fit.Cutting and pastingIPython is very forgiving when it comes to cutting and pasting in blocks of Python
code.  It will strip off the>>>prompt character and ignore indentation.  The normal
python REPL is not so forgiving.  IPython also allows maintains a command history and
allows command editing.Simple scriptingYou can write very simple scripts, for exampletest.pyisT=puma.fkine(puma.qn)sol=puma.ikine_LM(T)sol.qpuma.plot(sol.q);then$rvctooltest.py0010.5963010-0.1501-1000.65750001IKSolution(q=array([7.235e-08,-0.8335,0.09396,3.142,0.8312,-3.142]),success=True,iterations=15,searches=1,residual=1.406125546650288e-07,reason='Success')array([7.235e-08,-0.8335,0.09396,3.142,0.8312,-3.142])PyPlot3Dbackend,t=0.05,scene:robot:Text(0.0,0.0,'Puma 560')>>>and you are dropped into an IPython session after the script has run.Using Jupyter and ColabGraphics and animations are problematic in these environments, some things work
well, some don't.  As much as possible I've tweaked the Jupyter notebooks to work
as best they can in these environments.For local use theJupyter plugin for Visual Studio Codeis pretty decent.  Colab suffers
from old versions of major packages (though they are getting better at keeping up to date)
and animations can suffer from slow update over the network.Other command line toolsAdditional command line tools available (from the Robotics Toolbox) include:eigdemo, animation showing linear transformation of a rotating unit vector
which demonstrates eigenvalues and eigenvectors.tripleangledemo, Swift visualization that lets you experiment with various triple-angle sequences.twistdemo, Swift visualization that lets you experiment with 3D twists. The screw axis is the blue rod and you can
position and orient it using the sliders, and adjust its pitch. Then apply a rotation
about the screw using the bottom slider.Block diagram modelsBlock diagram models are key to the pedagogy of the RVC3 book and 25 models are
included. To simulate these models we use the Python packagebdsimwhich can run models:written in Python usingbdsimblocks and
wiring.created graphically usingbdeditand saved as a.bd(JSON format) file.The models are included in theRVC3package when it is installed andrvctooladds them to the module search path.  This means you can invoke them fromrvctoolby>>>%run-mvloop_testIf you want to directly access the folder containing the models, the command
line toolbdsim_pathwill display the full path to where they have been installed in the Python
package tree.Additional book resourcesThis GitHub repo provides additional resources for readers including:Jupyter notebooks containing all code lines from each chapter, see
thenotebooksfolderThe code to produce every Python/Matplotlib (2D) figure in the book, see thefiguresfolder3D points clouds from chapter 14, and the code to create them, see
thepointcloudsfolder.3D figures from chapters 2-3, 7-9, and the code to create them, see the3dfiguresfolder.All example scripts, see theexamplesfolder.To run the visual odometry example in Sect. 14.8.3 you need to download two image sequence, each over 100MB,see the instructions here.To get that material you must clone the repogitclonehttps://github.com/petercorke/RVC3-python.git