Skip to content

FutureFactoriesIE/robots

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

robots

This module allows for easy calculations and presentation of robots. The main component of the robots module is performing forward kinematics on the robot’s joint angles and plotting them on a graph using matplotlib. Velocities can also be calculated for each joint of the robot.

This README is a word-for-word copy of my original User Guide which can be found here.

The robots module itself can be found here.

Actual documentation can be found here.

Forward Kinematics

Calculating forward kinematics from joint angles is simple using the Robot class. Set the joint angles using the Robot.joint_angles property and call the get_fk_frames() method.

from robots import WhiteRobot
R01 = WhiteRobot()
R01.joint_angles = [0, 0, 90, 0, -90, 0]
frames = R01.get_fk_frames()

The output of this method is the result of calculating forward kinematics on the current robot’s joint angles (see the documentation for the actual return type). Therefore to find the actual position of joints, you will need to multiply each matrix by its previous matrices. While you can use the numpy @ operator and go frame by frame, the Robot class has a method that does this more efficiently:

position_frames = R01.get_accumulated_frames()

This method multiplies each frame returned from get_fk_frames() by its previous frames using itertools.accumulate, returning an iterator of the actual position/rotation frames of each of the robot’s joints.

Creating Plots

Creating visuals for the white and blue robots can be done in as few as 4 lines:

from robots import WhiteRobot
R01 = WhiteRobot()
R01.joint_angles = [0, 0, 90, 0, -90, 0]
plot_bytes = R01.get_plot()

The return value of get_plot() is a bytes representation of a plot in JPG format. To save the plot as an actual image file, use the save_plot() method instead.

R01.save_plot('plot')

plot.jpg plot.jpg

There is a secondary option for creating a plot: get_base64_plot(). This method returns a base64 encoded string of the plot, which can be used in conjunction with the edge-interface module to display the plot on a web interface.

An example of this is show below:

from edge_interface import EdgeInterface
from robots import WhiteRobot

interface = EdgeInterface(__name__)
interface.add_page('/', 'index.html')
interface.start_server()

R01 = WhiteRobot()
R01.joint_angles = [0, 0, 90, 0, -90, 0]

interface.pages['/'].set_image_base64('plot1', R01.get_base64_plot())

GIFs can also be created to show the path of the robot over time. Use the save_gif() method and pass in a list of lists of joint angles. A series of plots will be created for each list of joint angles passed in, which will then be combined sequentially to form a GIF.

from robots import WhiteRobot
R01 = WhiteRobot()
all_joint_angles = [
    [0, 0, 0.0, 0, 0, 0],
    [0, 0, 0.5, -1, 0, 0],
    [0, 0, 1.0, -2, 0, 0],
    [0, 0, 1.5, -3, 0, 0],
    [0, 0, 2.0, -4, 0, 0],
    [0, 0, 2.5, -5, 0, 0],
    [0, 0, 3.0, -6, 0, 0],
    [0, 0, 3.5, -7, 0, 0],
    [0, 0, 4.0, -8, 0, 0],
    [0, 0, 4.5, -9, 0, 0]
]
R01.save_gif(all_joint_angles, 'plot')

To change how the plots are rendered, as well as to add the tool history to the GIF, see the Configuring Plots section of this guide.

Configuring Plots

There are a few settings that can be configured to change the way the plot looks, as well as how fast the plot can be rendered. Each config option can be accessed using the Robot.plot_config attribute, which is a PlotConfig object. Changing these options is as simple as setting the attributes of this PlotConfig object.

from robots import WhiteRobot
R01 = WhiteRobot()

The default PlotConfig and joint_angles for the WhiteRobot will create plots that render like this:

plot-config-0.gif

Config Attribute Default Value Image
R01.plot_config.line_color = 'red' 'black' plot-config-1.gif
R01.plot_config.enable_tool_history = True False plot-config-2.gif
R01.plot_config.tool_history_color = 'green' 'blue' plot-config-3.gif
R01.plot_config.enable_axis_lines = True False plot-config-4.gif
R01.plot_config.axis_line_length = 100 50 plot-config-5.gif
R01.plot_config.enable_tool_position = False True plot-config-5.gif

Note: Some images are not loading correctly on GitHub, so to view them, use the link to the original User Guide here.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages