Saturday, 26 May 2012

It's all hooked up!

I've been slacking a little bit on keeping this blog up to date, but still progressing robot wise. My latest report is that I finally wired up the final components to MmBot - the Sabre Tooth 2x5 motor controller, and 2 quadrature encoders I have been building. Together they allow me to control MmBot's speed and direction quite accurately, and as result I will be able to reliably issue commands such as 'turn 90 degrees' or 'go forwards 3.5 metres'. First up though, here's MmBot in all her completeness:


And another one from above:


All parts are now attached and wired up. That's:
  • 2 Infra red range finders (front left/right)
  • 2 LinkSprite JPEG colour cameras (the eyes)
  • 1 Infra red motion detector (the nose)
  • 1 Ultra sound range finder (on top of head)
  • 2 quadrature encoders, each containing 2 infra red reflectivity sensors (next to the wheels)
  • 1 Blue smirf blue tooth modem
  • 1 Sabre tooth 2x5 motor controller
  • 2 18V DC geared motors
  • 1 Arduino Mega
The only bits missing are the interactive bits, which I may or may not add to this version of MmBot. These would be:
  • 1 speak jet voice/sound synthesizer (tested but not connected to MmBot)
  • 1 voice recognition chip
  • 2 led matrices
  • Speaker
  • Any extra leds I want to stick on!
While it'd be nice to get the interactive bits on as well, the circuitry is becoming a bit messy and I don't need it to achieve my initial goal of wandering around the office, identifying people or points of interest and looking cute. Plus my Raspberry Pi finally has a delivery date (3 weeks), and the cooler interactive stuff will be much easier and more powerful once it's hooked up.

The main thing I got working today though was the quadrature encoder and motor controller. This first fairly boring video shows the motor controller in action, gradually swinging the motors between full reverse and full forwards:



Next, things get a little more interesting. I start by asking both motors to go at 75% power and plonk MmBot down on the floor. Now you might hope that she would go in a straight line - after all I'm sending the same power to each motor. Unfortunately even in the best of scenarios motors aren't perfectly matched, and if you then introduce things like friction or wobbly wheels resulting from my supreme workmanship MmBot drives around in circles.

Not to worry though - that's why I built my encoders in the first place. These devices allow me to measure the actual speed the wheels are turning at. For MmBot to travel in a straight line both wheels need to turn at the same rate, so all I need to do is write some code which:
  • Supplies a fixed amount of power to left wheel (say 75%)
  • Initially supply the same amount of power to the right wheel
  • If the right wheel is going slower than the left wheel, supply it with more power
  • If the right wheel is going faster than the left wheel, supply it with less power
Sounds very simple, and it is in fact fairly simple. The only problem with this feedback type code is that the results aren't instantaneous - supplying more power to a wheel will allow it to reach a higher speed, but it takes time to have an effect. You have to be careful that your code accounts for this, or you'll find yourself constantly over compensating, and will end up driving all over the place!

You've seen my earlier code to read from the quadrature encoders, and other code to trigger sabre tooth motor controllers. this tiny bit of new code in the loop achieves speed control:

      //check where left encoder has got to relative to right encoder
      if(left_encoder_pos < right_encoder_pos)
      {
        //left is behind right, so we need to increase right motor speed
        motor_right_speed = min(255,motor_right_speed+1);
        MotorSerial.write(20);
        MotorSerial.write(motor_right_speed);    
        
        //and reset encoder positions (to avoid constant over compensation)
        left_encoder_pos = 0;
        right_encoder_pos = 0;
      }
      else if(left_encoder_pos > right_encoder_pos)
      {
        //left is ahead of right, so need to decrease right motor speed
        motor_right_speed = max(128,motor_right_speed-1);
        MotorSerial.write(20);
        MotorSerial.write(motor_right_speed);         

        //and reset encoder positions (to avoid constant over compensation)
        left_encoder_pos = 0;
        right_encoder_pos = 0;
      }

I wire up some switches on MmBot to turn on/off motors, and enable/disable speed control. This video shows the difference. Disclaimer: this is one of the worst filmed videos in the world, and my video editing abilities range from 0 to 0. I clearly need a tripod, a good camera and a lot of practice with AfterFx. Check out the start bit and the end bit, and pretend you never saw the middle bit.



And that's that! MmBot V1 is pretty much hardware complete. I'm in 2 minds now - I could go on and try to get some better code in there - take some steps towards autonomy. On the other hand, I now have a raspberry Pi in the post. Needs a bit of thought :)

-Chris

1 comment:

  1. ULANG TAHUN BOLAVITA YANG KE 6

    Sehubungan dengan ulang tahun Bolavita yg ke-6
    Bolavita sebagai Agen Taruhan Judi Online terbaik dan terpercaya akan menbagikan FREEBET & FREECHIP kepada member setia bola vita.

    FREEBET & FREECHIP hingga 2.000.000 (Dua juta rupiah)
    syarat dan ketentuan cek = https://bit.ly/2SsDinv

    Gabung sekarang dan klaim bonusnya!

    Info Lengkap :
    WA: 0812-2222-995 !
    BBM : BOLAVITA
    WeChat : BOLAVITA
    Line : cs_bolavita

    Info Togel =>> PREDIKSI TOGEL TERPERCAYA

    Agen Taruhan Judi Online

    ReplyDelete