12,401,324 members (34,544 online)
alternative version

21.7K views
14 bookmarked
Posted

# Basic Robot Control using NKH Mindsqualls Libraries

, 28 Aug 2010 CPOL
 Rate this:
Demonstration of how to do basic robot remote control via bluetooth using NKH Mindsqualls libraries.

## Introduction

This code demonstrates how to do some basic control of a lego nxt robot via a bluetooth connection. It uses the NKH Mindsqualls libraries available for free download and used to comunicate with a lego nxt brick. Search Mindsqalls in Google for the original download.

## Background

I was asked by a friend who just got his first Lego Mindstorms kit to produce a basic program in C# to show how to use C# and the Mindsqalls libraries. So here it is for anyone else who is having any problems.

## Using the Code

My code doesn't improve the NKH Mindsqalls classes but my Remote Control Panel and associated functions could be re-used in other programs.

This program is a basic application which has only two main parts:

1. MainForm - The main Windows form
2. Remote Control Panel - A user control I made that deals with running the robots motors

So how does it work. When the application starts, it runs MainForm. MainForm has 5 controls:

• 1. Remote Control Panel - The user control that deals with running the motors
• 2. Status Label - Tells the user what the program is doing
• 3 - 5. Sensor status labels - The statuses of Sensors 1 to 3 are displayed in these labels.

When MainForm runs, it loops through all the available com ports it can find trying to connect to an nxt. If no connection can be made, it tells the user and then exits as without a connection, the program is rendered useless and may as well exit. If a connection is made, the program sets up sensors 1 and 2 as touch sensors and sensor 3 as an ultrasonic sensor. For reasons unknown to me, NKH Mindsqualls libraries provide no function for determining what type of sensor is connected to any given port nor do the libraries support the standard colour sensor. For this reason, the type of sensors set up are hard coded and sensor 4 is left off for the obvious reason that many people only have the standard kit of which the fourth sensor (colour sensor) is not supported.

If all that is completed successfully, the application enables the Remote Control Panel and tells the user via the status label that an nxt is now connected. (To disconnect, the user must close the application.) The application will also warn the user every 30 seconds if their robot has low battery as bluetooth uses quite a lot of power.

The Remote Control Panel has two parts:

1. Setup
2. Running Controls

The setup can be changed at any time while the user is connected to their robot. The setup works on the idea that every time users wants to run a motor, they click the relevant button, the application checks the current settings against the last settings, if they are the same the motor(s) run(s) immediately; however, if they are different then all the motors are reset to the current settings and then the motors are run. In this way, the user can change quickly and easily which motors are drive motors and which (if any) is the auxiliary motor along with settings like drive power and turn ratio.

The running controls are separated into two parts:

1. Drive Motors (2 or 3)
2. Auxiliary Motor (1 or none) - Can also be set as steering

There have to be at least two drive motors, but there can be three. If there are only two drive motors, the code makes use of the Mindsqualls MotorPair class. This pairs two motors and guarantees (if not debugging while running the application) that the two motors will run in perfect sync with each other. If there are three drive motors, then the code manually tries to run them synchronously but unison is not guaranteed.

There does not have to be an auxiliary motor and if all three motors are set as drive motors, there isn't an auxiliary motor. If there is a spare motor, it is set as the auxiliary motor and has its own separate set of controls. However, the auxiliary motor can also be set to be used as steering so when the user wants to turn left or right, the auxiliary motor is used like a steering wheel.

For any robot programmer it's fairly basic, but if you are new to robot programming don't be put-off by it looking complicated. Most of it is the same code but with an option changed each time the code repeats. Have fun!

## Points of Interest

I found it annoying that there was no way to detect what type of sensor was actually connected to any given port and even more frustrating that the standard colour sensor isn't supported. Hopefully this will be fixed in the future :/.

## History

• 28th August, 2010: Initial post

## Share

 Student United Kingdom
Hi,

I am Edward Nutting, born March 1996 and I am currently a Computer Science and Electronic Engineering undergraduate at the University of Bristol, UK. I've been self-teaching programming since I was eight years old and have dabbled in many different areas from web development (where I had my own advertising startup) to low level operating system stuff (my current project Fling OS).

The articles and code on this profile are some of my early work (from when I was aged about 13 to 16) but despite my young age, it has been well received by CodeProject users. My more recent work has been for companies or on projects hosted on GitHub, CodePlex or BitBucket.

I keep an eye on many things techy and am open to any and all ideas, so please feel free to contact me if you think I can help!

Cheers,
Ed Nutting

## You may also be interested in...

 First Prev Next
 MindSqualls library is updated Mindsqualls21-Jul-11 0:33 Mindsqualls 21-Jul-11 0:33
 Basic Robot Control in VB.Net Programming code [modified] RoboTechNerd12-Apr-11 19:15 RoboTechNerd 12-Apr-11 19:15
 Re: Basic Robot Control in VB.Net Programming code EdMan19613-Apr-11 6:39 EdMan196 13-Apr-11 6:39
 I can not see the code... theo927311-Oct-10 3:01 theo9273 11-Oct-10 3:01
 My vote of 1 Phillip46530-Aug-10 22:35 Phillip465 30-Aug-10 22:35
 Last Visit: 31-Dec-99 18:00     Last Update: 27-Jul-16 3:21 Refresh 1