GithubHelp home page GithubHelp logo

mithi / hexapod-robot-simulator Goto Github PK

View Code? Open in Web Editor NEW
750.0 750.0 106.0 2.32 MB

A hexapod robot simulator built from first principles

License: MIT License

Python 84.36% CSS 15.32% Shell 0.30% Procfile 0.02%
dash hacktoberfest hexapod inverse-kinematics kinematics plotly plotly-dash plotly-example plotly-python robot robotics simulator

hexapod-robot-simulator's Introduction

hexapod-robot-simulator's People

Contributors

dependabot[bot] avatar guilyx avatar markkulube avatar mithi avatar philippeitis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hexapod-robot-simulator's Issues

Legs on ground must be on the xy plane

Currently the legs on ground is tilted with respect to the hexagon which is in the xy plane

the polygon defined by the legs on ground must be parallel to the xy plane,
it's the polygon which must be tilted

Draw the projection of the center of gravity on the ground plane

You'd need to update the following
1. The model VirtualHexapod to have an attribute that stores this point

class VirtualHexapod:

You can compute this point as outlined by the algorithm here, you should inject the point calculation to a different function and update the attribute of the VirtualHexapod when this is called in the two compute_orientation_properties of the hexapod.ground_contact_solver module.

def is_stable(p1, p2, p3, tol=0.001):

2. In figure template, you should append a new point trace at the end of the data list

The trace has the following format

    {
        "marker": {"color": INSERT_COLOR_HERE, "opacity": 1.0, "size": INSERT_SIZE_HERE},
        "mode": "markers",
        "name": "cog-projection",
        "type": "scatter3d",
        "x": [INSERT_COG_X_HERE],
        "y": [INSERT_COG_Y_HERE,
        "z": [0],
    }

3. HexapodPlotter could draw this point in the figure template

def _draw_hexapod(fig, hexapod):

Make text monospace

  • Hexapod robot dimensions label
  • Hexapod Robot dimensions input
  • Kinematics control input

Change Naming conventions (suggestions)

For each page we have a sort of block like this

GRAPH_NAME = "graph-kinematics"
ID_MESSAGE_SECTION = "message-kinematics"
ID_PARAMETERS_SECTION = "parameters-kinematics"

sidebar = shared.make_standard_sidebar(
    ID_MESSAGE_SECTION, ID_PARAMETERS_SECTION, SECTION_POSE_CONTROL
)

layout = shared.make_standard_page_layout(GRAPH_NAME, sidebar)

outputs, inputs, states = shared.make_standard_page_inputs_outputs_states(
    GRAPH_NAME, ID_PARAMETERS_SECTION, ID_MESSAGE_SECTION
)

I'm not a fan of the variable names
maybe something like

graph_id
parameters_section_id
message_section_id

respectively is more meaningful and appropriate

Refactoring Suggestions

Replace:

header = dcc.Markdown(

With:

div_header = html.Div(
    [
        html.A(html.H6("👾"), href=URL_REPO, target="_blank", style=icon_link_style),
        html.A(html.H6("☕"), href=URL_KOFI, target="_blank", style=icon_link_style),
        dcc.Link(html.H6("●"), href="/", style=icon_link_style),
        dcc.Link(html.H6("●"), href="/inverse-kinematics", style=icon_link_style),
        dcc.Link(html.H6("●"), href="/kinematics", style=icon_link_style),
    ],
    style={"display": "flex", "flex-direction": "row"}
)

So that the page does not not refresh

Reimplement ik_solver (2.0) module

Reimplement inverse kinematics solver (hexapod.ik_solver2). The current implementation hexapod.ik_solver involves a bunch of tiny helper methods and one big god function that tries to do almost everything. I plan to redesign this by making a class that centers around this responsibility.

Should determine how body twists around its z axis

How to determine how the hexagon body will twist around its z axis?

Ideas:

given pose before and pose after

determine which leg points are on the ground
on both before and after.

This points are the "pivot" points.

which means the shape of the polygon defined by these points
should be the same in the pose before and the pose after.

get any point in this set.

the angle between the vector A and B
where A is the vector from center of gravity to point in old pose
and B is the vector from center of gravity to point in new pose.

is the angle of the twist???

Modify to be more pythonic

Legs can criss-cross each other

You shouldn't be able to do that,

Check adjacent legs if they're going to crash to each other.
Prevent this by just rotating at the best acceptable range (increment by 5 degrees maybe?)

❗Algorithm for computing hexapod orientation does not account for all cases

❗❗❗

The old algorithm rests upon the assumption that it knows which point of the each leg is in contact with the ground. This assumption seems to be true for all possible cases for
leg-patterns page and inverse-kinematics page.

But this is not true for all possible angle combinations (18 angles) that can be defined in
the kinematics page.

This current algorithm will still be used for the leg-patterns page, and the inverse-kinematics page. A more general algorithm will be used for the kinematics page

The following algorithm can be used for the leg-patterns page and inverse-kinematics page.
(How to find the ground contact points, tilt, and height of the hexapod)

But this can't be used in general.
This is because how we determine the ground contact ie Linkage.compute_ground_contact() doesn't always yield the correct result.

def compute_ground_contact(self):

Here's the new algorithm that accounts for most cases

Hexapod does not remember most recent old pose

The way it works right now is,

for each update, a new hexapod is created from scratch (all angles = 0)
and then the hexapod poses is built from there on.

It would be better if we remember the old hexapod pose, especially for computing twists along the z axis.

Rename Point class to Vector

We are using the Point class for 3d Vectors as well. I think the Point name is loaded, Vector is a more generalized term for a set of three numbers

Refactor pages

We currently have three pages apart from the landing page

  • The inverse kinematics page
  • The kinematics page
  • The leg patterns page

All of them have the following:

GRAPH_NAME = "graph-hexapod-patterns"
ID_MESSAGE_DISPLAY_SECTION = "display-message-patterns"
SECTION_MESSAGE_DISPLAY = html.Div(id=ID_MESSAGE_DISPLAY_SECTION)
ID_POSES_SECTION = "hexapod-poses-values-patterns"
SECTION_HIDDEN_JOINT_POSES = html.Div(id=ID_POSES_SECTION, style={"display": "none"})

SECTION_CONTROLS = [
    SECTION_DIMENSION_CONTROL,
    *insert_widget_section_here*,
    SECTION_MESSAGE_DISPLAY,
    SECTION_HIDDEN_BODY_DIMENSIONS,
    *insert_hidden_parameters_here*,
]

They also have something like this

OUTPUT_MESSAGE_DISPLAY = Output(ID_MESSAGE_DISPLAY_SECTION, "children")
INPUT_POSES_JSON = Input(*insert parameter section_id_here*, "children")
OUTPUTS = [Output(GRAPH_NAME, "figure"), OUTPUT_MESSAGE_DISPLAY]
INPUTS = [INPUT_DIMENSIONS_JSON, INPUT_POSES_JSON]
STATES = [State(GRAPH_NAME, "relayoutData"), State(GRAPH_NAME, "figure")]

We can refactor this into the shared module

Error Handling for IK Solver

Currently this is how we do it:

@app.callback(OUTPUTS, INPUTS, STATES)
def update_inverse_page(dimensions_json, ik_parameters_json, relayout_data, figure):
    if figure is None:
        return BASE_FIGURE, ""

    dimensions = helpers.load_dimensions(dimensions_json)
    hexapod = VirtualHexapod(dimensions)
    ik_parameters = json.loads(ik_parameters_json)
    hexapod, poses, alert = inverse_kinematics_update(hexapod, ik_parameters)

    if RECOMPUTE_HEXAPOD and poses:
        hexapod = recompute_hexapod(dimensions, ik_parameters, poses)

    BASE_PLOTTER.update(figure, hexapod)
    helpers.change_camera_view(figure, relayout_data)

    if poses:
        text = helpers.make_poses_message(poses)
    else:
        text = helpers.make_alert_message(alert)

    return figure, text

We can do something like this

@app.callback(OUTPUTS, INPUTS, STATES)
def update_inverse_page(dimensions_json, ik_parameters_json, relayout_data, figure):
    if figure is None:
        return BASE_FIGURE, ""

    ik_parameters = json.loads(ik_parameters_json)
    dimensions = helpers.load_dimensions(dimensions_json)
    hexapod = VirtualHexapod(dimensions)

    try:
        hexapod, poses = inverse_kinematics_update(hexapod, ik_parameters)
    except Exception as e:
        return figure, helpers.make_alert_message(e)

    if RECOMPUTE_HEXAPOD :
        hexapod = recompute_hexapod(dimensions, ik_parameters, poses)

    BASE_PLOTTER.update(figure, hexapod)
    helpers.change_camera_view(figure, relayout_data)
    return figure, helpers.make_poses_message(poses)

Make hexapod graph colors and sizes customizable

  • floor color
  • paper color
  • body outline color
  • body mesh color
  • support polygon color
  • cog color
  • leg color
  • legends paper color
  • cog size
  • head size
  • joint sizes
  • line sizes - hexapod polygon
  • line sizes - hexapod legs

Checklist of todos for features to implement in the IK solver

Notes:

  • limit beta and gamma ranges
  • Limit alpha to range between -90 to 90
  • When all left side or right side is above ground, make this an impossible pose.
  • Name the updated points of the updated hexapod their correct names, right now they're names is None

Wrong behavior in IK page

This is bug when RECOMPUTE_HEXAPOD = True in settings.py

The issue can be replicated by moving
percent.z slider or percent.y slider

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.