Controlling Motors using C# Library from Unity 3D

General discussion of using Roboclaw motor controllers
Post Reply
Posts: 1
Joined: Wed May 18, 2022 6:11 pm
Controlling Motors using C# Library from Unity 3D

Post by admantium »

Hello! I have recently bought Roboclaw controllers through recommendations from the Pololu community.

My goal is to control the motors to reflect an event going on in a Unity 3D app using C#.

I did download the C# library provided by Basicmicro, but without examples, I am unable to utilize the code by itself or inside of Unity 3D.

I did find plenty of Arduino example codes provided by Basicmicro, but failed to find any using C#.

I would appreciate any assistance, especially on a way to use the C# library from within a Unity 3D script.

Thank you for reading!
User avatar
Basicmicro Support
Posts: 1594
Joined: Thu Feb 26, 2015 9:45 pm
Re: Controlling Motors using C# Library from Unity 3D

Post by Basicmicro Support »

Note: The C# library has been updated(today).

The starting point is to reference the Roboclaw library.

Then derive a class from the Roboclaw class or create a Roboclaw object directly.

There is a static Find function in the Roboclaw class which will return a list of all attached Roboclaw controllers. This returns a list of strings for the Roboclaw models and their comport numbers(comport is in ()s).

When you create Roboclaw object(I'll call it "rc" from here on) you have to specify the comport, baudrate and packet serial address(eg 0x80 thru 0x87). Baudrate can be any value if you are using USB.

You then need to call rc.Open

Then you can, optionally, use the rc.GetVersion command to check the connected controller is using the correct firmware.

Then you can use any of the Packet Serial functions(eg Set and Get commands and movement commands).

There are a lot of helper functions mostly used by the library(you should mostly ignore these unless you are an advanced programmer) and there are some CANOpen handling functions(MCP only and outside this simple tutorials scope).

And that is about it. If you have specific questions please open a support ticket from the Contact Us page.

Post Reply