AdolphSmith

9 years ago

I have Used a ATMEGA328 + DUAL Motor Controller ( https://www.robotics.org.za/index.php?route=product/product&product_id=…) as driver for my DC Servo motor. 

Inside also a Rotary Encoder ( https://www.robotics.org.za/index.php?route=product/search&search=rotar… ) . 

So the small ATMEGA328 Board need a small program inside that read my rotary encoder and turn the motor to the position he recieve from the Ardiuno Mega pin 8 . So when ArdiunoMeg give command like to a servo he must respond same way as servo.

Can you do this. Or do i understood it wrong what is possable.

Thank you

Adolph

 

Adolph

 

Ahoy Adolph,

I would have answered you sooner, but I'm in Germany working.  Lots of work work... long days here and jet lag make me want to sleep when I'm done with the day.

But I think this is a great project you are working on !

The first thing which came to mind .. 

I think its impressive you want to make this "behave" like a servo, but I think your trying TO HARD !  Bit-Banging an RC signal would be ineffecient and prone to errors.

I would prefer to support it from MRL as a real DC Motor with a single channel encoder. 

Which means you should not need the additional Mega to be connected to it.  I believe you can directly connect an FTDI cable to it.  So you'd run MRLComm.ino on the motor controller directly.  

There are only 2 pieces which would need to be added.

  1. MRLComm.ino needs to support a DC Motor with a single encoder such that MRL can send the motor to moveTo(170)  and MRLComm.ino would start the DC motor at a specified and appropriate PWM speed.  Count the nnumber of pulses from the encoder, and stop (possibly ramp down) the motor at the appropriate 170 pulse.
  2. Motor and Servo need a common interface in MRL-land .. So that you can use any of the Python scripts currently written for a Servo to work on your new "Motor-Servo" 

Does this sound desirable to you?

Grog please i must realy tri. Any small program that i can tri load in the Baby Arunutang please. It have like the picture shows buildt in motor driver and have everything. I know you can do this please

 

Perfect Adolph !

Ok - They have a library, we do not want it - but I need to find out details about the H-Bridge.

Clever product tiny Arduino + Dual H-Bridge - theoretically, you should be able to drive Massive Adolph Servos from this board.  I see it uses pwm for speed control which is what I would expect - what I don't see at the moment is if its a :

  • Evil Dirty H-Bridge - where direction and speed are controlled on the same line but 2 pins - and it has a evil shoot-through state  .. or
  • Happy Good H-Bridge - where direction pin is seperate from the speed pin

I'm hoping for the latter - but haven't found the answer yet.

GroG

9 years ago

In reply to by GroG

Good news its a Happy Good H-Bridge !!!

So it looks like a simple pwm pin for speed & direction is on another pin...

We need to find out exactly what pins your current motor is hooked up to - what are they?

The next step would be to make a very small sketch which drives the motor WITHOUT Pololu's Motor library.

Have you driven this motor with Pololu's Motor library yet?

What experiments have you done so far Adolph?

Adolph, did you try uploading a sketch to use the baby board without encoder? The encoder can be added easely, if you test with the scripts from the polulu site, you can test speed, direction and so, and after grog gets back i think he can build a simple sketch with an encoder in it to use as dc motor/servo  with poti.

Small simple steps will win the Race !

Step 1

Cause and effect - upload a simple blink program, does it work ?
Unplug everything from the Atmega 328 if you need too except the FDTI cable.
This is the first check. If it worky - you say "WORKY !"  and we move on to Step 2 - if it no worky - we find out why..

Sory Grog what i ment was that blink leds working but other things not like motors.I have tested with blink led yes. Worky. Now for something in scrip that let motors run. Because all the scrips available need pot to get motors running. I do not use pot .

 

I looked at some of the documentation & the libraries code.

I "think" PWM power is controlled by pin 6.  If that is correct a simple analog write should change the motors speed.

Try this 

[[home/GroG/servoMotor.c]]

If that works we can start thinking about the feedback of the encoder.  I hope your still interested in doing this ! 

 

// F_CPU tells util/delay.h our clock frequency
//#define F_CPU 8000000UL // Orangutan frequency (8MHz)
#define F_CPU 20000000UL // Baby Orangutan frequency (20MHz)
#include <avr/io.h>
#include <util/delay.h>
 
void delayms( uint16_t millis ) {
while ( millis ) {
_delay_ms( 1 );
millis--;
}
}
 
int main( void ) {
DDRD |= 1 << DDD1; // set LED pin PD1 to output
while ( 1 ) {
PORTD &= ~( 1 << PORTD1 ); // LED off
delayms( 900 ); // delay 900 ms
PORTD |= 1 << PORTD1; // LED on
delayms( 100 ); // delay 100 ms
}
return 0;
}
 

Arduino: 1.6.3 (Windows 7), Board: "Pololu Orangutan or 3pi robot w/ ATmega328P"
 
sketch_apr26e.ino:1:27: fatal error: orangutanleds.h: No such file or directory
 
compilation terminated.
 
Error compiling.
 
  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.
 

#include <OrangutanLEDs.h>
#include <OrangutanAnalog.h>
#include <OrangutanMotors.h>
 
/*
 * OrangutanMotorExample for the 3pi robot, Orangutan LV-168, Orangutan SV-xx8,
 *   and Baby Orangutan B
 *
 * This example uses the OrangutanMotors library to drive
 * motors in response to the position of user trimmer potentiometer
 * and blinks the red user LED at a rate determined by the trimmer
 * potentiometer position.  It uses the OrangutanAnalog library to measure
 * the trimpot position, and it uses the OrangutanLEDs library to provide
 * limited feedback with the red user LED.
 *
 */
  
OrangutanAnalog analog;
OrangutanLEDs leds;
OrangutanMotors motors;
  
void setup()               // run once, when the sketch starts
{
  
}
  
void loop()                // run over and over again
{
  //                  M1   M2
  motors.setSpeeds(128, 128);
   
  pinMode(1, OUTPUT);
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);
  pinMode(14, OUTPUT);
  pinMode(15, OUTPUT);
  pinMode(16, OUTPUT);
 
  // PIN MAPPINGS M1 POWER PD5 == Pin 12
  analogWrite(1, 128);
  digitalWrite(40, 0);
  delay(1000);
  analogWrite(48, 128);
  digitalWrite(2, 0);
  delay(1000);
  analogWrite(55, 128);
  digitalWrite(3, 0);
  delay(1000);
  analogWrite(65, 128);
  digitalWrite(4, 0);
  delay(1000);
  analogWrite(45, 128);
  digitalWrite(5, 0);
  delay(1000);
  analogWrite(66, 128);
  digitalWrite(6, 0);
  delay(1000);
  analogWrite(77, 128);
  digitalWrite(7, 0);
  delay(1000);
  analogWrite(88, 128);
  digitalWrite(8, 0);
  delay(1000);
  analogWrite(59, 128);
  digitalWrite(9, 0);
  delay(1000);
  analogWrite(120, 128);
  digitalWrite(10, 0);
  delay(1000);
  analogWrite(111, 128);
  digitalWrite(11, 0);
  delay(1000);
  analogWrite(88, 128);
  digitalWrite(12, 0);
  delay(1000);
  analogWrite(93, 128);
  digitalWrite(13, 0);
  delay(1000);
  analogWrite(74, 128);
  digitalWrite(14, 0);
  delay(1000);
  analogWrite(85, 128);
  digitalWrite(15, 0);
  delay(1000);
  analogWrite(56, 128);
  digitalWrite(16, 0);
  delay(1000);
    
  leds.red(HIGH);       // turn red LED on
  delay(128);
  
  leds.red(LOW);       // turn red LED off
  delay(128);
}
 

So when you comment out 

//motors.setSpeeds(128, 128);

it doesn't work ?

That's the goal Adolph, not to use the motors.setSpeed and still be able to move the motors .. :)

If you do //motors.setSpeeds(128, 128);

nothing turn