Hi guys. Hope you can help.
I am trying to make a simple robot move in all directions. I have 5 possible combinations to make the robot manuver: forward, reverse, left, right and full stop.
There are 2 VEX motor modules. (3 wires: +, - and signal wire).
According to VEX site: 'The Vex Motor will require about 700us of low time on the control signal input before the next pulses rising edge. Therefore the total pulse time is about 1.7ms to 2.7ms yielding an input frequency rate of about 370 Hz to 588 Hz.'
That is straight forward and very easy to implement using the PWM class.
Problem: when in ‘reverse’ only one of the motors works. All other combinations work.
Is there a problem with the PWM class? Running latest firmware.
I really want to use the PWM class to take advantage of the hardware PWM.
Declarations:
private static PWM leftMotor = new PWM((PWM.Pin)FEZ_Pin.PWM.Di10);
private static PWM rightMotor = new PWM((PWM.Pin)FEZ_Pin.PWM.Di9);
Code to set robot direction:
private static void SetDirection(Direction newDirection)
{
if (newDirection == CurrentDirection)
return;
Debug.Print("new direction: '" + newDirection.ToString() + "'\r\n");
CurrentDirection = newDirection;
if (newDirection == Direction.None)
{
leftMotor.SetPulse(0, 0);
rightMotor.SetPulse(0, 0);
}
else if (newDirection == Direction.Forward)
{
leftMotor.SetPulse(1700 * 1000, 1000 * 1000);
rightMotor.SetPulse(2700 * 1000, 2000 * 1000);
}
else if (newDirection == Direction.Reverse)
{
leftMotor.SetPulse(2700 * 1000, 2000 * 1000);
rightMotor.SetPulse(1700 * 1000, 1000 * 1000);
}
else if (newDirection == Direction.Left)
{
leftMotor.SetPulse(2700 * 1000, 2000 * 1000);
rightMotor.SetPulse(2700 * 1000, 2000 * 1000);
}
else if (newDirection == Direction.Right)
{
leftMotor.SetPulse(1700 * 1000, 1000 * 1000);
rightMotor.SetPulse(1700 * 1000, 1000 * 1000);
}
}