Motor Driver (Gadgeteer on Raptor)

Can anyone tell me why the following code does not work on a Raptor?

using System.Threading;
using Bauland.Gadgeteer;
using GHIElectronics.TinyCLR.Pins;

namespace TinyCLR_PTZ
{
    class Program
    {
        static void Main()
        {
            var motorDriver = new MotorDriverL298(
                0x58,
                0x52,
                FEZRaptor.PwmChannel.Controller1.Socket18.Pin8,
                FEZRaptor.PwmChannel.Controller2.Socket18.Pin9,
                FEZRaptor.PwmChannel.Controller1.Id,
                FEZRaptor.PwmChannel.Controller2.Id);

            var motor1 = MotorDriverL298.Motor.Motor1;
            var motor2 = MotorDriverL298.Motor.Motor2;

            while (true)
            {
                
                motorDriver.SetSpeed(motor1, 0.7);
                Thread.Sleep(2000);
                motorDriver.SetSpeed(motor1, 0.9);
                Thread.Sleep(2000);
                motorDriver.SetSpeed(motor1, -0.75);
                Thread.Sleep(2000);
                motorDriver.StopAll();
                Thread.Sleep(2000);


                motorDriver.SetSpeed(motor2, 0.7);
                Thread.Sleep(2000);
                motorDriver.SetSpeed(motor2, 0.9);
                Thread.Sleep(2000);
                motorDriver.SetSpeed(motor2, -0.75);
                Thread.Sleep(2000);
                motorDriver.StopAll();
                Thread.Sleep(2000);
            }


        }
    }
}

If I remove motor1, everything seems to work fine, but when I add motor2, motors start working randomly!

1 Like

Well, it seems there are 2 problems…

The first one is that the Baulands driver XML for the initialiser has the wrong pin mappings! The second one is that the FEZ Raptor has buggy firmware, as the same code works just fine on the FezSpiderII

For info, here is the code:

using System.Threading;
using Bauland.Gadgeteer;
using GHIElectronics.TinyCLR.Pins;

namespace TinyCLR_PTZ
{
    class Program
    {
        static void Main()
        {
            //var motorDriver = new MotorDriverL298(
            //    AT91SAM9X35.GpioPin.PC24, //Socket 18 Pin 6 not available through FezRaptor.GpioPin
            //    AT91SAM9X35.GpioPin.PC20, //Socket 18 Pin 9 not available through FezRaptor.GpioPin
            //    FEZRaptor.PwmChannel.Controller1.Socket18.Pin8,
            //    FEZRaptor.PwmChannel.Controller0.Socket18.Pin7,
            //    FEZRaptor.PwmChannel.Controller1.Id,
            //    FEZRaptor.PwmChannel.Controller0.Id
            //    );

            var motorDriver = new MotorDriverL298(
                FEZSpiderII.GpioPin.Socket11.Pin6,
                FEZSpiderII.GpioPin.Socket11.Pin9,
                FEZSpiderII.PwmChannel.Controller0.Socket11.Pin8,
                FEZSpiderII.PwmChannel.Controller1.Socket11.Pin7,
                FEZSpiderII.PwmChannel.Controller0.Id,
                FEZSpiderII.PwmChannel.Controller1.Id
                );
            


            var motor1 = MotorDriverL298.Motor.Motor1;
            var motor2 = MotorDriverL298.Motor.Motor2;

            while (true)
            {                
                motorDriver.SetSpeed(motor1, 0.7);
                Thread.Sleep(2000);
                motorDriver.SetSpeed(motor1, 0.9);
                Thread.Sleep(2000);
                motorDriver.SetSpeed(motor1, -0.75);
                Thread.Sleep(2000);
                motorDriver.StopAll();
                Thread.Sleep(2000);


                motorDriver.SetSpeed(motor2, 0.7);
                Thread.Sleep(2000);
                motorDriver.SetSpeed(motor2, 0.9);
                Thread.Sleep(2000);
                motorDriver.SetSpeed(motor2, -0.75);
                Thread.Sleep(2000);
                motorDriver.StopAll();
                Thread.Sleep(2000);
            }


        }
    }
}
1 Like

I added to my todo list !