Controlling robots from inside AutoCAD – Part 1

Happy New Year! I hope that those of you who celebrate at this time of year, were able to take a nice, relaxing break. I certainly did. 🙂

Anyway, it's now time for me to ease back into work. But rather than it being an abrupt transition, I've decided to take a look at a pet project that I thought would be pretty fun: controlling robots from inside AutoCAD. The thinking is to outline some possibilities for moving virtual robots inside a floorplan drawing and having their real-world, physical counterparts move as instructed. Perhaps along a specific path, perhaps by finding a path based on the current 2D floorplan… we'll see what makes most sense as we go along.

But let's start with the basics, such as which robots to use. In the Walmsley household we had a number of them under the tree, this Christmas: I bought a Sphero BB-8 and my wife bought a LEGO Mindstorms EV3 construction system, both ostensibly "for the kids". Thankfully it seems I'm also covered by that particular description, so I get to mess around with them now that the actual kids are back in their respective classrooms.

I haven't cracked open the EV3 set, as yet, but we already had a lot of fun with BB-8, over the break. For those of you who missed the fuss, this is the "real" BB-8 from Star Wars: The Force Awakens:

BB-8

The Sphero version of BB-8 is pretty darn cool. Here's the marketing video:

 

 

This little bot is typically controlled by mobile apps that make use of Bluetooth Low Energy, much as its siblings the classic Sphero and the Ollie are. To take control of it from my PC, I decided to use Cylon.js, a JavaScript robotics framework that integrates with a number of different robot and Internet of Things platforms. I definitely see more IoT fun in my near future, so it seemed to make sense to use this rather than a Sphero-specific SDK of some kind.

It seems a little quirky to be using a JavaScript framework on a physical PC (or Mac) to send instructions to a nearby device, but there are some likely advantages, down the line: it would certainly make it easier to have the controller physically independent of the robotic environment, having it driven remotely via a web-page or -service on (for instance) a Raspberry Pi with a Node server and a Bluetooth dongle. And in the meantime AutoCAD can host the page or call the service on the same system via localhost.

When getting started, this post helped quite a bit, as well as this one it points to. To simplify the act of getting BB-8 to work, I also integrated keyboard support into my Cylon code using this snippet.

Oh, and just to do something that goes beyond what the existing mobile apps can do, I added support for multiple devices. Here's some JavaScript code that controls both the new BB-8 and last year's Christmas present, the Ollie:

 

 

And here's the code in action. I cycle through a sequence of four commands – front, left, right, backwards – and as the robots are facing in opposite directions they end up in the same place.

 

 

To make this work I applied different durations for the "roll" operations for each type of robot: given its design, the Ollie is somewhat grippier and more responsive, so I used a roll duration of 600ms vs. 1.5 seconds for BB-8.

Now that we can see how easy it is to control these robots from JavaScript, now I have to work out how to plug this into AutoCAD. The step after that will probably involve decomposing AutoCAD "path" geometry into movement operations. I believe these bots can also provide collision detection feedback, too… maybe we can use that to generate a crude map of a floorspace, too!

8 responses to “Controlling robots from inside AutoCAD – Part 1”

  1. You're code doesn't seem to show up. Maybe it's my version of IE? But it's not showing up on Chrome either.

    1. That's strange. It works fine for me in Chrome and Firefox on my Mac and IE11 on my PC. I'm using Gist to host the code for this one... here's the direct link, in case:

      gist.github.com/Kea...

      1. I think that answered my question. At the office we are blocked from GitHub. I can see it on my personal device though. Thanks!

        1. Interesting datapoint. I've been considering moving all my code to GitHub. I'll consider this is a vote against that...

  2. I'm seeing the code correctly, in IE.
    Can you make AutoCAD talk to an Arduino? I have a netduino that I started playing with a while back, but its more expensive. So for simple goals, have acad make an LED light go on or off depending on blipmode. Also, turn blipmode on when a switch is activated. Those things would require gathering info, and acting on it so should set the stage for more complicated things so we can make our own interface devices.

    1. These days you can make pretty much anything with an IP address talk to anything else (assuming you have some knowledge of/control over the data being sent). So it's certainly possible. I'm going to be looking at ways of doing this (and other IoT-related things) as we move further into the IoT space.

      Kean

      1. That is a weak area of my skills. I would be interested to see how simple that can work. I probably need to research it a bit on my own so I at least have seen a few approaches.

  3. Nice!
    I can maybe get my phone back from my son now.

Leave a Reply to JeffH Cancel reply

Your email address will not be published. Required fields are marked *