our swiss φθηνα ρολογια are all in now.
Before the end of this year, I wanted to enrich my uPLibrary a new managed driver for the dual motor driver TB6612FNG that I used earlier this year in a demo at the Microsoft Embedded Conference 2013 on a robot equipped with a Netduino Plus and piloted through the Kinect (thanks to Clement Giorio).
The dual motor driver
This Toshiba motor driver allows to drive two DC motors (Direct Current) with a maximum power of 15 V and with four operating modes: CW (ClockWise), CCW (CounterClockWise), short brake and stop. Also, the speed of each motor can be varied through a PWM (Pulse Width Modulation) by changing the duty cycle.
On the Sparkfun website a useful breakout board that mounts the motor control and makes it easily accessible pins is available.
The managed driver
The managed driver that allows the use of dual motor driver is represented by the TB6612FNG class that provides two contructors through which you can decide whether to use just one or both engines. For each engine is called a channel (A and B) characterized by:
The first two signals are represented by two instances of the OutputPort class for each channel and the last signal is represented by an instance of the PWM class.
The constructor makes provides the use of channel A only while the more complex prepares the object to the use of both motors (also recalling the simpler constructor).
1: public TB6612FNG(Cpu.Pin aIn1, Cpu.Pin aIn2, Cpu.PWMChannel aPwmChannel,
2: Cpu.Pin bIn1, Cpu.Pin bIn2, Cpu.PWMChannel bPwmChannel,
3: Cpu.Pin standby = Cpu.Pin.GPIO_NONE)
4: : this(aIn1, aIn2, aPwmChannel, standby)
6: this.bIn1Port = new OutputPort(bIn1, false);
7: this.bIn2Port = new OutputPort(bIn2, false);
9: this.bPwm = new PWM(bPwmChannel, DEFAULT_PWM_FREQUENCY, 0, false);
11: this.IsMotorEnabledB = true;
12: this.MotorModeB = MotorMode.Stop;
The application that uses the managed driver can interact with the dual motor driver through some properties (and not methods) to enable them, set the operating mode and speed. If we refer to the channel A we have respectively the following properties IsMotorEnabledA, MotorModeA and MotorSpeedA . Each of these properties acting on pins dedicated to OutputPort above (for the operation mode) and on the PWM pin (for speed, with a value from 0 to 100).
1: /// <summary>
2: /// Mode for Motor A
3: /// </summary>
4: public MotorMode MotorModeA
8: if (this.IsMotorEnabledA)
9: return this.motorModeA;
11: throw new ApplicationException("Motor A is disabled !!");
15: switch (value)
17: case MotorMode.CCW:
18: this.motorModeA = MotorMode.CCW;
22: case MotorMode.CW:
23: this.motorModeA = MotorMode.CW;
27: case MotorMode.ShortBrake:
28: this.motorModeA = MotorMode.ShortBrake;
32: case MotorMode.Stop:
33: this.motorModeA = MotorMode.Stop;
43: /// <summary>
44: /// Speed for Motor A
45: /// </summary>
46: public int MotorSpeedA
50: if (this.IsMotorEnabledA)
51: return this.motorSpeedA;
53: throw new ApplicationException("Motor A is disabled !!");
57: if ((value >= 0) && (value <= 100))
58: this.motorSpeedA = value;
59: this.aPwm.DutyCycle = (double)this.motorSpeedA / 100;
For example, in the case of a robot with two wheels and therefore two motors driven by this driver, we could develop a method that active both in the same direction to advance or retract the robot, or a method that active both in opposite directions to make it turn.
1: // both motors in counter clockwise mode
2: this.tb6612fng.MotorModeA = MotorMode.CCW;
3: this.tb6612fng.MotorModeB = MotorMode.CCW;
7: this.tb6612fng.MotorModeA = MotorMode.CW;
8: this.tb6612fng.MotorModeB = MotorMode.CCW;
The library is at version 2.2 and it is available on Nuget and on CodePlex. Unfortunately, the dual motor driver support is guaranteed for .NET Micro Framework 4.2 and above but the version 4.1 is excluded, because it is not available the PWM class.
View this page in another language: