Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Motors not working properly - urgent


  • Please log in to reply
7 replies to this topic

#1 Ben Harel

Ben Harel

    Advanced Member

  • Members
  • PipPipPip
  • 32 posts

Posted 22 May 2013 - 06:36 PM

Hi!

I have a platform(tracked) with two engines. I want to write a simple program that moves the car forward, backward and spin both directions. I used the following circuit, from the netmftoolbox documentation.

http://netmftoolbox....ailable classes

 

The code doesn't work for me for some reason, the engines do what ever they want.

I am trying to use a code I found on YouTube(modified for my use and the 4.2 version), here is the code:

 

class Motor
    {
        private OutputPort directionPort;
        private PWM velocityPort;
        private uint velocity;
        private bool direction;
        public const bool Forward = true;
        public const bool Backward = false;
 
 
        public Motor(int PWMPortNum,Cpu.Pin pinForDirection)
        {
            //
            switch (PWMPortNum)
            {
                case 3: velocityPort = new PWM(PWMChannels.PWM_PIN_D3, 1000, 0.5, false); break;
                case 5: velocityPort = new PWM(PWMChannels.PWM_PIN_D5, 1000, 0.5, false); break;
                case 6: velocityPort = new PWM(PWMChannels.PWM_PIN_D6, 1000, 0.5, false); break;
                case 9: velocityPort = new PWM(PWMChannels.PWM_PIN_D9, 1000, 0.5, false); break;
                case 10: velocityPort = new PWM(PWMChannels.PWM_PIN_D10, 1000, 0.5, false); break;
                case 11: velocityPort = new PWM(PWMChannels.PWM_PIN_D11, 1000, 0.5, false); break;
                default: velocityPort = new PWM(PWMChannels.PWM_PIN_D5, 1000, 0.5, false); break;
            }
 
            directionPort = new OutputPort(pinForDirection, false);
            directionPort.DisableInterrupt();
        }
 
        public void Stop()
        {
            this.Velocity = 0;
            this.velocityPort.Stop();
        }
 
        public bool Direction
        {
            get { return this.direction; }
            set
            {
                this.direction = value;
                UpdateDirection();
            }
        }
 
        public uint Velocity
        {
            get { return this.velocity; }
            set
            {
                this.velocity = value;
                UpdateVelocity();
            }
        }
 
        private void UpdateVelocity()
        {
            velocityPort.DutyCycle = velocity;
            velocityPort.Start();
        }
 
        private void UpdateDirection()
        {
            directionPort.Write(Direction);
        }
    }

-------------------------------------------------------------------------

 class DriveSystem
    {
        private Motor leftMotor;
        private Motor rightMotor;
 
        public DriveSystem()
        {
            rightMotor = new Motor(5, Pins.GPIO_PIN_D4);
            leftMotor = new Motor(6, Pins.GPIO_PIN_D7);
        }
 
        public void Stop()
        {
            leftMotor.Stop();
            rightMotor.Stop();
        }
 
        public void SetLeftSpeed(uint speed)
        {
            leftMotor.Velocity = speed;
        }
 
        public void SetRightSpeed(uint speed)
        {
            rightMotor.Velocity = speed;
        }
    }

--------------------------------------------

 public class Program
    {
        public static void Main()
        {
            DriveSystem driveSystem = new DriveSystem();
            driveSystem.SetLeftSpeed(100);
            driveSystem.SetRightSpeed(1);
            Thread.Sleep(5000);
            driveSystem.Stop();
            driveSystem.SetLeftSpeed(1);
            driveSystem.SetRightSpeed(100);
            Thread.Sleep(5000);
            driveSystem.Stop();
            driveSystem.SetLeftSpeed(50);
            driveSystem.SetRightSpeed(50);
            Thread.Sleep(5000);
            driveSystem.Stop();
         
 
        }
 
    }

 

 

 

 

The robot is not moving if I give zero speed value to one of my motors. But the code above only moves one motor(the first) and at the second one - nothing. Only when it gets to the part when both of them should go it - it works.

 

 

I am in desperate need of help. I busted my head trying to get it working for the last month, and the project is due tomorrow.(My project is a robot controlled by motion captured from a camera, so I need the robot...)

Thank you

 



#2 Paul Newton

Paul Newton

    Advanced Member

  • Members
  • PipPipPip
  • 724 posts
  • LocationBerkshire, UK

Posted 22 May 2013 - 07:41 PM

Hi Ben,

 

Looking at the hardware:

There is no power supply shown in the diagram you linked to.

 

Do you have a Vin supply going to the barrel connector of the netduino (or directly onto the bread board)?

or are you powering the Netduino from 5V USB?

 

If you only have a 5V input to the Netduino, then I am guessing your motors don't have any power.

 

The motor driver needs a hefty power supply - I have found its a bad idea to draw power for motors through the Netduino's PCB. I also found it was a bad idea even to share a power supply (unexplained resets).

 

I now prefer to supply motors with a separate battery pack to the supply for the logic.

In my own buggy I use 6xAA for the motor driver to use, and a separate USB emergency phone charger battery to give 5V for the Netduino.

 

Looking at the software:

Try something really simple!

Forget PWM, just setup the GPIO as normal ON/OFF outputs and try turning the motors ON, then try reversing them.

This will prove the circuitry works.

Then try replacing the GPIO ON/OFF with PWM.

 

Hope this helps - Paul



#3 Ben Harel

Ben Harel

    Advanced Member

  • Members
  • PipPipPip
  • 32 posts

Posted 22 May 2013 - 08:07 PM

Yes, I connected a power supply to the Netduino.

About the software, I'll try that and report back. Thank you!

 

EDIT

Wait!

How do I set up the PWM? I gave it 1000 as frequency, is that good?



#4 Ben Harel

Ben Harel

    Advanced Member

  • Members
  • PipPipPip
  • 32 posts

Posted 22 May 2013 - 08:16 PM

And how do I reverse the motors? Reversing the cables?

 

oh I got it



#5 Ben Harel

Ben Harel

    Advanced Member

  • Members
  • PipPipPip
  • 32 posts

Posted 22 May 2013 - 10:31 PM

Hi Ben,

 

Looking at the hardware:

There is no power supply shown in the diagram you linked to.

 

Do you have a Vin supply going to the barrel connector of the netduino (or directly onto the bread board)?

or are you powering the Netduino from 5V USB?

 

If you only have a 5V input to the Netduino, then I am guessing your motors don't have any power.

 

The motor driver needs a hefty power supply - I have found its a bad idea to draw power for motors through the Netduino's PCB. I also found it was a bad idea even to share a power supply (unexplained resets).

 

I now prefer to supply motors with a separate battery pack to the supply for the logic.

In my own buggy I use 6xAA for the motor driver to use, and a separate USB emergency phone charger battery to give 5V for the Netduino.

 

Looking at the software:

Try something really simple!

Forget PWM, just setup the GPIO as normal ON/OFF outputs and try turning the motors ON, then try reversing them.

This will prove the circuitry works.

Then try replacing the GPIO ON/OFF with PWM.

 

Hope this helps - Paul

 

Hi.

The left engine for some reason does not work, heres the code:

OutputPort left = new OutputPort(Pins.GPIO_PIN_D4, false);
OutputPort right = new OutputPort(Pins.GPIO_PIN_D10, false);
Thread.Sleep(5000);
right.Write(true);
left.Write(true);
Thread.Sleep(5000);
 
All of the cables are ok, and if I connect the replace cables between right engine and left engine the left works and the right one is not.


#6 Paul Newton

Paul Newton

    Advanced Member

  • Members
  • PipPipPip
  • 724 posts
  • LocationBerkshire, UK

Posted 23 May 2013 - 05:42 AM

Sounds like the motor circuit is OK, but there is something wrong with the GPIOs. Possibly D4 is damaged. Try again with a different GPIO instead of D4. Then see if you can yet both motors running. I don't have access to my code right now to check the pwm frequency.

#7 Ben Harel

Ben Harel

    Advanced Member

  • Members
  • PipPipPip
  • 32 posts

Posted 23 May 2013 - 07:19 AM

Sounds like the motor circuit is OK, but there is something wrong with the GPIOs. Possibly D4 is damaged. Try again with a different GPIO instead of D4. Then see if you can yet both motors running. I don't have access to my code right now to check the pwm frequency.

 

 

 

 

 

I tried D2, still nothing.



#8 Paul Newton

Paul Newton

    Advanced Member

  • Members
  • PipPipPip
  • 724 posts
  • LocationBerkshire, UK

Posted 23 May 2013 - 08:45 AM

Have you enabled the direction contol GPIOs? If you have just left them floating that may be a problem. Enable them or connect to ground to ensure a valid logic level.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.