Adding new controllers?

So I am wondering if I have to use java to add a new motor controller?

I am using a dagu 4 motor controller that uses two inputs for each motor, pwm and direction, and it also offers encoders and current sensing for each motor

Just curious as to how to add a new controller.

GroG's picture

WHOOOHOOO !

MRL currently has a Motor service (http://myrobotlab.org/service/Motor)  It should control it just fine with your two input pins .. as the example script shows

arduino.motorAttach("m1", 9, 8) 

will initialize it with the two pins 

For the encoder you can just use the Arduino service to poll the pin (there is even debounce setting you can use, but I bet OddBot designed it pretty well so it might not be necessary to debounce in software)

Set it up, and we will help you take CONTROL !! :D

GroG's picture

PS - find an Avatar you like

PS - find an Avatar you like !

Grinanbarrett's picture

Hmm, I thought that the

Hmm, I thought that the arduino motor control was for an hbridge. Where there could be 3 pins, enable, then two direction pins. With this controller I have two pins per motor, pwm for speed and control, high goes forward and low reverses.

Am I misunderstanding?

GroG's picture

IMHO - I believe all simple

IMHO - I believe all simple H-bridges should be implemented with 2 bit control where
1st - bit speed/pwm
2nd - bit direction

and that is the way the Arduino service motor control works

Arduino.motorAttach(String motorName, Integer PWMPin, Integer directionPin) 

So its a match with your hardware.

Grinanbarrett's picture

  Man that is cool?   I will

 

Man that is cool?   I will be testing tonite for sure

Grinanbarrett's picture

Ok so I played with this last

Ok so I played with this last night. And it works just as you said., but there is another question that I have about this.

I am using 5v power from my laptop to power the drive wheels, I can see an obvious difference in speed when using mrl vs arduino control.

Is there a way to specify pwm frequency?

GroG's picture

In the sketch you use with

In the sketch you use with the Arduino - do you modify the PWM or timers?

 

Grinanbarrett's picture

No

I will have to look at the exact sketch when I get off work, but not that I recall. 

I think I simply pulsed the line at full pwm and then gave a high signal to the direction pin. Will post the sketch in a bit. 

GroG's picture

I'd like to know how they

I'd like to know how they behave differently.. (post a video if you can) they should behave the same, unless you did modify the timers.. but MRL even has the capability to set the PWM at a different frequency... (you have to be careful not to mess up the serial connection when you do - it relies on some of the timers)

I had to do this, because I wanted to avoid the high pitch whine and I have a few motors which like much low frequencies...

Grinanbarrett's picture

Ok, I will see what i can do

Ok, I will see what i can do about a small clip or two of the motors spinning..

BUT, I didn't notice this last night, but check out the PWM, 127, that's half power.. so, there is a difference for sure.  I will turn up the pwm to 255 which should be full power, and video that and full power via MRL and post a video.

Here's the code that is currently loaded on one arduino (RBBLeo) and the standard MRL arduino sketch is loaded as well on another RBBLeo. 

###################################################################

#define LM1D_pin 5   
#define LM2D_pin 7      
#define RM1D_pin 9      
#define RM2D_pin 11      
#define Right_Speed 4    
#define Right_Speed2 6   
#define Left_Speed 8     
#define Left_Speed2 10   

void setup()
{
  pinMode (LM1D_pin,OUTPUT);                     // configure Left Motor Direction pin as output
  pinMode (LM2D_pin,OUTPUT);
  pinMode (RM1D_pin,OUTPUT);
  pinMode (RM2D_pin,OUTPUT);
  pinMode (Right_Speed, OUTPUT);
  pinMode (Right_Speed2, OUTPUT);
  pinMode (Left_Speed, OUTPUT);
  pinMode (Left_Speed2, OUTPUT);
}

void loop()
{
 
// DRIVE FORWARD FOREVER

  digitalWrite(LM1D_pin, HIGH);
  digitalWrite(LM2D_pin, LOW);
  digitalWrite(RM1D_pin, HIGH);
  digitalWrite(RM2D_pin, LOW);
 
  analogWrite(Right_Speed, 127);
  analogWrite(Right_Speed2, 127);
  analogWrite(Left_Speed, 127);
  analogWrite(Left_Speed2, 127);
 
  }

#########################################################################

Video to come

GroG's picture

why are you looping through

why are you looping through the digital and analog writes?

what is the result ?  Does the Arduino sketch go faster or slower than MRL ?

An Arduino can maintain a PWM on a pin after a single analogWrite - you are writing direction & speed commands (the same ones) many times per second.  

In otherwords all the code you have could and I "think" probably should be in the setup.  If you dynamically changed speed - then you might have that in the loop .. e.g. analogWrite(Right_Speed, newSpeedValue) -> then delay(5000) // wait 5 seconds - then go to the next speed..

What kind of motor controller or h-bridge do you have ?

We need pictures & specification, links etc.. :D