Mikrobus.Net Quail Robot

In a previous post I had replaced a Netduino and Elecfreaks Joystick shield based remote control with a MikrobusNet Quail, thumbstick click and an nRF-C click. The next step was to replace the Netduino on the robot chassis with a MikrobusNet Quail, a pair of DC Motor Clicks and an nRF-C click.

Bill of materials (prices in USD as at Feb 2016)

The first version of the robot uses a pair of battery packs one for the motors the other for the Quail board.

MikrobusNetQual4WDRobot

The drivers developed by MikroBUSNet team greatly reduced the amount of code I had to write to get the robot to work.

public class Program
{
   private static double Scale = 100.0;
   private static byte RobotControlChannel = 10;
   private static byte[] ControllerAddress = Encoding.UTF8.GetBytes("RC1");
   private static byte[] RobotAddress = Encoding.UTF8.GetBytes("RB1");
   private static TimeSpan MessageMaximumInterval = new TimeSpan(0, 0, 1);
   private static DateTime _MessageLastReceivedAt = DateTime.UtcNow;
   private static DCMotorClick motor1 = new DCMotorClick(Hardware.SocketOne);
   private static DCMotorClick motor2 = new DCMotorClick(Hardware.SocketTwo);

public static void Main()
{
   NRFC nrf = new NRFC(Hardware.SocketFour);
   nrf.Configure(RobotAddress, RobotControlChannel);
   nrf.OnTransmitFailed += nrf_OnTransmitFailed;
   nrf.OnTransmitSuccess += nrf_OnTransmitSuccess;
   nrf.OnDataReceived += nrf_OnDataReceived;
   nrf.Enable();

   Timer CommunicationsMonitorTimer = new Timer(CommunicationsMonitorTimerProc, null, 500, 500);

   Thread.Sleep(Timeout.Infinite);
}

static void nrf_OnDataReceived(byte[] data)
{
   Hardware.Led1.Write(true);
   _MessageLastReceivedAt = DateTime.UtcNow;

   if (data.Length != 5)
   {
   return;
   }

   Debug.Print("M1D=" + data[0].ToString() + " M2D=" + data[1].ToString() + " M1S=" + data[2].ToString() + " M2S=" + data[3].ToString());
   if (data[0] == 1)
   {
      motor1.Move(DCMotorClick.Directions.Forward, (data[2] / Scale ));
   }
   else
   {
     motor1.Move(DCMotorClick.Directions.Backward, (data[2] / Scale ));
   }

   if (data[1] == 1)
   {
      motor2.Move(DCMotorClick.Directions.Forward, (data[3] / Scale ));
   }
   else
   {
      motor2.Move(DCMotorClick.Directions.Backward, (data[3] / Scale ));
   }
}

private static void CommunicationsMonitorTimerProc(object status)
{
   if ((DateTime.UtcNow - _MessageLastReceivedAt) > MessageMaximumInterval)
   {
      Debug.Print("Communications timeout");

      motor1.Move(MBN.Modules.DCMotorClick.Directions.Forward, 0.0);
      motor2.Move(MBN.Modules.DCMotorClick.Directions.Forward, 0.0);
   }
}

I have kept the communications monitoring functionality which stops the motors when the robot gets out of range of the remote control software fails.

 

 

 

Mikrobus.Net Quail Robot Remote Control

In a previous pair of posts  (part1 & part2) in February 2014 I built a 4WD Robot and remote control using a pair of Netduinos, an elecfreaks Smart Car Chassis 4WD, an elecfreaks joystick 2.4, an Embedded coolness nRF24Lo1 shield and a Pololu MC33926 motor shield.

My Quail device looked like a good platform for building a handheld control with a different form factor.

Bill of materials (prices in USD as at Jan 2016)

Quail4WDRobotController

The Quail device and battery pack aren’t quite small enough to work with one hand. A Mikrobus.Net Dalmatian or Tuatara based remote might be easier to use.

I tried using the thumbstick button pushed message for the horn functionality but it made the throttle and heading jump.

The first version of the code is just to test the wireless link, the motor speed code needs a little work.(Currently the device won’t rotate with motors going in opposite directions)

public class Program
{
   private const double Deadband = 0.1;
   private static double Scale = 100.0;
   private static byte RobotControlChannel = 10;
   private static byte[] ControllerAddress = Encoding.UTF8.GetBytes("RC1");
   private static byte[] RobotAddress = Encoding.UTF8.GetBytes("RB1");

   public static void Main()
   {
      ThumbstickClick thumbStick = new ThumbstickClick(Hardware.SocketThree);
      thumbStick.ThumbstickOrientation = ThumbstickClick.Orientation.RotateZeroDegrees;
      thumbStick.Calibrate();

      NRFC nrf = new NRFC(Hardware.SocketFour);
      nrf.Configure(ControllerAddress, RobotControlChannel );
      nrf.OnTransmitFailed += nrf_OnTransmitFailed;
      nrf.OnTransmitSuccess += nrf_OnTransmitSuccess;
      nrf.Enable();

      while (true)
      {
         byte motor1Direction, motor2Direction;
         byte motor1Speed, motor2Speed;
         double x = thumbStick.GetPosition().X;
         double y = thumbStick.GetPosition().Y;

         Debug.Print("X=: + x.ToString("F1") + " Y=" + y.ToString("F1") + " IsPressed=" + thumbStick.IsPressed);

         // See if joystick x or y is in centre deadband
         if (System.Math.Abs(x) < Deadband)
         {
            x = 0.0;
         }

         // See if joystick y is in centre deadband
         if (System.Math.Abs(y) < Deadband)
         {
            y = 0.0;
         }

         // Set direction of both motors, no swivel on spot yet
         if (y >= 0.0)
         {
            motor1Direction = (byte)1;
            motor2Direction = (byte)1;
         }
         else
         {
            motor1Direction = (byte)0;
            motor2Direction = (byte)0;
         }

         // Straight ahead/backward
         if (x == 0.0)
         {
            motor1Speed = (byte)(System.Math.Abs(y) * Scale);
            motor2Speed = (byte)(System.Math.Abs(y) * Scale);
         }
         // Turning right
         else if (x > 0.0)
         {
            motor1Speed = (byte)(System.Math.Abs(y) * Scale);
            motor2Speed = (byte)(System.Math.Abs(y) * (1.0 - System.Math.Abs(x)) * Scale);
         }
         // Turning left
         else
         {
            motor1Speed = (byte)(System.Math.Abs(y) * (1.0 - System.Math.Abs(x)) * Scale);
            motor2Speed = (byte)(System.Math.Abs(y) * Scale);
         }

         Debug.Print("X=" + x.ToString("F1") + " Y=" + y.ToString("F1") + " IsPressed=" + thumbStick.IsPressed + " M1D=" + motor1Direction.ToString() + " M2D=" + motor2Direction.ToString() + " M1S=" + motor1Speed.ToString() + " M2S=" + motor2Speed.ToString());

         byte[] command =
         {
            motor1Direction,
            motor2Direction,
            motor1Speed,
            motor2Speed,
            (byte)0)
         };
         nrf.SendTo(RobotAddress, command );

         MBN.Hardware.Led1.Write(true);

         Thread.Sleep(250);
      }
   }

   static void nrf_OnTransmitSuccess()
   {
     MBN.Hardware.Led1.Write(false);
     Debug.Print("nrf_OnTransmitSuccess");
   }

   static void nrf_OnTransmitFailed()
   {
      Debug.Print("nrf_OnTransmitFailed");
   }
}

The Mikrobus.Net team have done a great job with the number and quality of the drivers for the Mikroe click boards. The Mikroe click boards are individually packaged with professionally written click specific and handling instructions.

Remote control 4WD robot build part2

I finally had some time to finish off the 4WD robot I first blogged about in February this year.

robot and remote control

Netduino 4wd robot and remote control unit

When I fired up the robot the nrf24L01 module on the embedded coolness shield was having some problems with electrical noise from the motors. This noise was causing the wireless module to report errors then stop working. So, based on this article by Pololu I added some noise suppression capacitors. There are two 0.1uF capacitors per motor and they connect the power supply pins to the metal casing of the motor. I have also twisted the motor supply wires and added some capacitors to the motor shield.

Motors with noise suppression capacitors

Netduino 4WD Robot motors with noise suppression capacitors

The Elecfreaks Joystick has to be modified to work with a Netduino. The remote control uses the initial position of the joystick for a calibration offset then sends 4 byte commands to the robot every 250mSec. The first two bytes are the motor directions and the last two are the motor speeds.

_module.OnDataReceived += OnReceive;
_module.OnTransmitFailed += OnSendFailure;
_module.OnTransmitSuccess += OnSendSuccess;

_module.Initialize(SPI.SPI_module.SPI1, Pins.GPIO_PIN_D10, Pins.GPIO_PIN_D9, Pins.GPIO_PIN_D1);
_module.Configure(_ControllerAddress, channel);
_module.Enable();

xOffset = xAxis.Read();
yOffset = yAxis.Read();

_timer = new Timer(SendMessage, null, 250, 250);
Thread.Sleep(Timeout.Infinite);

Then

byte[] command = { motor1Direction, motor2Direction, motor1Speed, motor2Speed };
_module.SendTo(_RobotAddress, command);

After trialling the robot round the house I added a timer to shut the motors down if connectivity was lost. Before adding the noise suppression capacitors I managed to plough the robot into the wall when the radio link failed and the motors were running at close to full speed.

Timer CommunicationsMonitorTimer = newTimer(CommunicationsMonitorTimerProc, null, 500, 500);
void CommunicationsMonitorTimerProc(object status)
{
   if (( DateTime.UtcNow - _MessageLastReceivedAt ) > MessageMaximumInterval)
   {
      Debug.Print(&quot;Communications timeout&quot;);
      M1Speed.DutyCycle = 0.0;
      M2Speed.DutyCycle = 0.0;
   }
}

Remote control 4WD robot build part1

A couple of parcels of parts arrived last week and I have started assembling my next robot project (possibly for code club). It’s a 4WD drive robot with an nRF24L01+ based remote control.

Robot chassis

ElecFreaks 4WD Robot and Remote

Had a slight problem with pin usage, the Embedded Coolness nRF24L01 shield and Pololu Dual MC33926 Motor Shield both use pin D2(irq) & D7(csn). The polulu shield supports some customising of pins so I disconnected D2(Status flag indicator), cut the D7 link (Motor 1 direction input) and wired it to pin D5.

modified motor shield

Pololu Dual MC33926 Modifications

I’m using the nRF24l01 driver from codeplex as basis for both ends of my remote control, code to follow…

Bill of materials (Prices USD as at Feb 2014)

 

Netduino Plus and nRF24L01 module shield

A fortnight ago I purchased two shields from Embedded Coolness for a couple of nRF24L01 based projects (quadcopter & robot control system) I’m working on.The shields were very reasonably priced and took roughly 10-15 minutes each to assemble.

Embedded Coolness nRF24L01+ Shield

nRF24L01 Shield with short range module

Though intended for Arduino based projects the hardware SPI port works with the Nordic nRF24L01 .Net Micro Framework Driver on Codeplex.

I adapted the sample application included with the Nordic nRF24L01 .Net Micro Framework Driver source from codeplex to give a minimal working Netduino example.

...
public class EmbeddCoolnessTestHarness
{
private const byte channel = 10;
private readonly OutputPort _led = new OutputPort(Pins.ONBOARD_LED, false);
private readonly NRF24L01Plus _module;
private Timer _timer;
private byte _token;
private readonly byte[] _myAddress = Encoding.UTF8.GetBytes("NetP1");
private readonly byte[] _otherBoard = Encoding.UTF8.GetBytes("NetP2");

public EmbeddCoolnessTestHarness()
{
_module = new NRF24L01Plus();
}

public void Run()
{
_module.OnDataReceived += OnReceive;
_module.OnTransmitFailed += OnSendFailure;
_module.OnTransmitSuccess += OnSendSuccess;

// we need to call Initialize() and Configure() before we start using the module
_module.Initialize(SPI.SPI_module.SPI1, Pins.GPIO_PIN_D7, Pins.GPIO_PIN_D3, Pins.GPIO_PIN_D2);
_module.Configure(_myAddress, channel);
_module.Enable();

_timer = new Timer(SendMessage, null, new TimeSpan(0, 0, 0, 1), new TimeSpan(0, 0, 0, 1));
}

private void OnSendSuccess()
{
_led.Write(false);
}

private void OnSendFailure()
{
Debug.Print("Send failed!");
}

private void OnReceive(byte[] data)
{
Debug.Print("Token = " + data[0]);
}

private void SendMessage(object state)
{
_led.Write(true);
_module.SendTo(_otherBoard, new[] { _token });
_token++;
}
}