Mechanism2D Questions

Hi all,

I was working on a simple simulation, which includes a single jointed arm. Naturally, I created the well-documented sim controller for this object, but I also want to visualize it. I noticed Mechniasm2D, but there is a strong lack of documentation, and I am unsure of how it works. If anyone could provide insight (from any language, although I use Python), that would be great.

I am particularly curious about the ligament path parameters.

Thanks!

@Peter_Johnson might know

Yes, there are no docs on this yet–we wanted to move this to NetworkTables (as we did with Field2D) but didn’t get it done in time for kickoff.

In the current implementation, you need to create a json file describing the body and how the ligaments are connected, e.g.:

{
  "name":  "Test",
  "backgroundColor": "green",
  "body": [
    {
      "name": "one",
      "type": "line",
      "startLocation": 0,
      "lineWidth": 3,
      "length": 10,
      "color": "blue",
      "angle": 0,
      "children":[
        {
          "name": "two",
          "type": "line",
          "lineWidth": 3,
          "length": 10,
          "color": "green",
          "angle": 0
        }
      ]
    }
  ]
}

Then in your robot program, create a Mechanism2D object. Calling setLigamentAngle("Test/one/two", angleInDegrees) will set the relative angle between the line segments one and two.

Our plan for future improvement here is to move this entirely to NetworkTables so no json file is needed (it would be entirely defined via the Mechanism2D API) and multiple mechanisms can be created.

1 Like

Thank you very much! I look forward to seeing it!

@Peter_Johnson I just tried, it but I’m afraid it didn’t work with these values. Any ideas why?

{
    "name":  "Test",
    "backgroundColor": "green",
    "body": [
      {
        "name": "one",
        "type": "line",
        "startLocation": 10,
        "lineWidth": 30,
        "length": 100,
        "color": "blue",
        "angle": 45,
        "children":[
          {
            "name": "two",
            "type": "line",
            "lineWidth": 30,
            "length": 100,
            "color": "green",
            "angle": 45
          }
        ]
      }
    ]
  }