Skip to main content

Python module for designing mechanisms and robots

Project description

Brian Mechanisms

Brian Mechanisms is a Python module designed for engineers and developers to easily design and simulate various mechanical mechanisms and robots. It provides a collection of tools and algorithms for kinematic analysis, motion planning, and visualization of mechanical systems.

Features

  • Kinematic analysis for various types of mechanisms, including linkages, gears, and robotic arms.
  • Motion planning algorithms for path generation and trajectory optimization.
  • Visualization tools to create interactive plots and animations of mechanical systems.
  • Integration with popular libraries such as NumPy and Matplotlib for scientific computing and visualization.

Installation

ou can install Brian Mechanisms using pip:

Copy code
pip install brianmechanisms

Usage

Locii

The Locii class is used for plotting and/or animating output paths of rigid link mechanisms with a θ input. Each link has a number of points whose lengths are given relative to the pivot point for that mechanism. The pivot point has its length set to 0.

Link Configuration

Each link is defined by a dictionary containing the following keys:

  • points: A dictionary defining the points on the link and their respective lengths.
  • speed: The speed of the link (optional).
  • equation: A string representing the equation for the displacement of the link.
  • origin: The origin point of the link.
  • len_factor: A length factor for scaling the link (optional).
  • speed_factor: A factor for scaling the speed of the link (optional).
  • speed_source: The source of the speed, referencing another link's speed (optional).
  • theta0: The initial angle for the link (optional).
  • output: The output point of the link (optional).

Example of defining links:

link1 = {
    "points": {
         "O": 0, "A": 1
    },
    "speed": 1,
    "equation": "np.cos(x), np.sin(x)",
    "origin": "{0,0}"
}

link2 = {
    "points": {
        "A": 0, "B": 1
    },
    "len_factor": 1,
    "speed_factor": 2,
    "speed_source": "link1.speed",
    "equation": "np.cos(speed_factor * speed_source * x), np.sin(speed_factor * speed_source * x)",
    "origin": "link1.A",
    "theta0": 1,
    "output": "B"
}

Plotting the Locus

By default, the function will plot the loci of all the given points of the mechanism using dashed lines. The output is plotted using a solid line, specified by the output property in the link's settings.

Plotting the Mechanism

To draw the mechanism in addition to the loci, define the mechanism_theta property. The mechanism will be drawn at 0 = mechanism_theta.

Examples

Tusi Couple

This example demonstrates how to define links and use the Locii class to plot and animate the Tusi Couple mechanism.

from brianmechanisms import Locii
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
import numpy as np

link1 = {
    "points": {
         "O": 0, "A": 1
    },
    "speed": 1,
    "equation": "np.cos(x), np.sin(x)",
    "origin": "{0,0}"
}

link2 = {
    "points": {
        "A": 0, "B": 1
    },
    "len_factor": 1,
    "speed_factor": 1,
    "speed_source": "link1.speed",
    "equation": "np.cos(speed_factor * speed_source * x), np.sin(speed_factor * speed_source * x)",
    "origin": "link1.A",
    "theta0": 1,
    "output": "B"
}

linksTemplate = {
    "link1": link1.copy(),
    "link2": link2.copy()
}

fig, axs = plt.subplots(1, 1)
locii = Locii(linksTemplate, {})
fig, ax = locii.plotOutPutPaths(title={"title": "Tusi Couple", "sub": "Subtitle Example"}, plotConfig={"ax": axs, "fig": fig, "legend": False, "axes": False, "mechanism_theta": 45, "ani": True})

ani3 = FuncAnimation(fig, locii.update, frames=np.arange(0, 360, 10), fargs=(ax, {"title": "Example Plot", "sub": "Subtitle Example"}, {"ax": axs, "fig": fig, "legend": False, "axes": False, "mechanism_theta": 45, "ani": True}), interval=100)

plt.show()

HTML(ani3.to_jshtml())
Animating and Saving the Animation

To animate the plot and save it as a video file (e.g., MP4), use the FuncAnimation class from matplotlib.animation and specify the writer (e.g., FFMpegWriter):

from matplotlib.animation import FFMpegWriter

writer = FFMpegWriter(fps=10, metadata={'title': 'Tusi Couple', 'artist': 'brianmechanisms', 'comment': 'Tusi Couple Animation'})
ani3.save('tusicouple.mp4', writer=writer)

This documentation provides a basic overview of how to use the brianmechanisms module, specifically focusing on the Locii class for plotting and animating rigid link mechanisms. For more detailed information and additional features, refer to the official documentation and examples provided in the module.

plotConfig Settings

The plotConfig dictionary allows you to customize various aspects of your plot and animation. Here are the key settings you can use:

-ax: Specifies the Matplotlib axes object to use for plotting. If not provided, a new axes object will be created.

  • fig: Specifies the Matplotlib figure object to use for the plot. This allows you to add the plot to an existing figure.
  • legend: A boolean flag that controls whether a legend should be displayed on the plot. If set to False, no legend will be shown.
  • axes: A boolean flag that controls whether the axes should be displayed on the plot. If set to False, the axes will be hidden.
  • mechanism_theta: Specifies the angle (in degrees) at which the mechanism should be drawn. This setting allows you to visualize the mechanism at a specific angle.
  • ani: A boolean flag that indicates whether the plot should be animated. If set to True, the animation will be enabled.

Hypocycloids

Tusi Couple

Tusi Couple

Hypocycloids

Hypoctrochoids

Epictrochoids

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

brianmechanisms-0.1.20.tar.gz (39.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

brianmechanisms-0.1.20-py3-none-any.whl (57.1 kB view details)

Uploaded Python 3

File details

Details for the file brianmechanisms-0.1.20.tar.gz.

File metadata

  • Download URL: brianmechanisms-0.1.20.tar.gz
  • Upload date:
  • Size: 39.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for brianmechanisms-0.1.20.tar.gz
Algorithm Hash digest
SHA256 30ffcfa8bf74dfb1ee0fa4e3234ba48ecc98367f0d1c65340f35ab0533504d48
MD5 abba0770988d3d829c5bd2cab20e02ca
BLAKE2b-256 3e2ffb88f5f97f5a53fdd517e79cc3dc68efd46271a27b57caa396b1b418afdc

See more details on using hashes here.

File details

Details for the file brianmechanisms-0.1.20-py3-none-any.whl.

File metadata

File hashes

Hashes for brianmechanisms-0.1.20-py3-none-any.whl
Algorithm Hash digest
SHA256 63aa0f4ba8dd30690370e0a65c2635db4cad2d3b18b8c8be63e53ec82325a096
MD5 4e3a0abfc5a710446728f3cdaee12b0d
BLAKE2b-256 e0f2bdce94afd0b7706fc5ecf6ed26fc0e438855a545005e72199ab8d7ea0323

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page