loading
 
Sparkfun_Mega
Vibot from Canada  [2 posts]
6 years
Hi
I am using the program for obstacle avoidance and the motor controllers are connected to arduino mega. But when i try to control the motors, they are very slow. In my VB script the speeds are 200 but i am not get that output from PWM pins. I have loaded the sketch file given under mega module.

Am i doing anything wrong? The direction pins give me 5V but i only get 0.55V from PWM pins. Please advise. Attached is my robo file.

Your help will be highly appreciated.
RoboRealm_Arduino_Mega.zip
program.robo
Anonymous 6 years
Vibot,

The issue is with the actual numbers being sent. Some servo controllers use 0 to 255 ... which is NOT the case with the Arduino. In many MCU's the range is 500 to 2500 which reflects the ms timing for servos directly. The 0 to 255 range is also converted into this range but that is done at the hardware level.

So in your case change the values in the VBScript to either 1700 or 1300 depending on the direction you want the motors to move. Note that is this case 1500 is zero or neutral. So 1700 and 1300 should move your bot slowly ... if they are too slow and do not move the machine increase or decrease the values.

i.e.

SetVariable "right_motor", 1300

or

SetVariable "right_motor", 1700

etc.

But be sure to test things first with the bot elevated (on blocks).

STeven.
Vibot from Canada  [2 posts] 6 years
Steven

I have tried this out and has also set the speed upto 5500 but no improvement was seen. I was still getting output voltage of 0.5V.

So now i have decided to use serial module and control speed using Arduino mega. I hope there is no glitches with Arduino mega sketch which has been provided.

Thanks for your feedback and hope to get more guidance in future from you.

Vibot

Anonymous 6 years
Vibot,

You may want to verify that communications with the Arduino is working correctly. The easiest way to do this is to toggle the Digital IO pin 13 on and off using the GUI checkbox and see if the Arudino complies with this action. If not, then it is probably a COM problem, if it does, then its probably a power/programming issue.

STeven.
Raj from Fiji  [9 posts] 6 years
Well this is what i have came up with to communicate from RR to arduino using serial module which is faster for me. This script can take 3bit of data from RR and pass it to arduino for other control algorithms. This is really handy if anyone wants to control the motor through motor controllers using Arduino and RR.

void loop()
{
  // Wait for data to become available at the serial port
while(!Serial.available()){}

while(Serial.available())
{
  StrArray[i] = Serial.read() - '0';

  delay(1);
   i++;
}

  if(i==4)
    x = StrArray[0]*1000 + StrArray[1]*100 + StrArray[2]*10 + StrArray[3];
  if(i==3)
    x = StrArray[0]*100 + StrArray[1]*10 + StrArray[2];
  if(i==2)
    x = StrArray[0]*10 + StrArray[1];
  if(i==1)
    x = StrArray[0];  
    
     i=0;
    
   highest_middle_x = x;// this can be any variable from RR.

For me i was more interested in Highest middle x of the image processed so anyone can change and modify.

For this works for other guys who might want to do similar jobs.

Anonymous 6 years
hi steve
I am also trying to do very similar work but i can't get the output on my arduino mega. Even when the values are 2500, the voltage output is below 1V.

Has this Arduino mega module being tested by you. I would appreciate if you can test and send me the codes. I Have attached the robo file which i am using. Arduino mega is loaded with file provided on the RR site.

Your guidance will help me alot.

Edwin Vans
program.robo
Anonymous 6 years
Steven

Today i tried to change the arduino board and i tested it with arduino duemilanove board with the required sketches. When i move the slider on the pwm GUI, the voltage output on the pwm pins only reach up to 0.6V max. the digital pins are giving me 5v as required, but i am not able to drive my motors with pwm pins since the output is very low. The arduino board is powered by usb so that i can communicate to RR.

What else should i do to solve the problem? Could you please verify the arduino sketches given since few of us are facing the same problem.

Arduino module will be very handy for robot control, but if we can get the pwm, then it becomes quite difficult to read the data in arduino serially using serial module....

Anonymous 6 years
Edwin,

Can you confirm what you are connecting those PWM pins to? Are they servos or DC motors?

Note that the PWM signal will not give you full voltage since the signal varies and it will depend on how your voltmeter behaves as to what it does when it sees a signal cycling at about 20ms.

Regardless, we'll check the Arduino code as we've used the Mega a lot lately and have not checked the basic Arduino in a while.

STeven.
Anonymous 6 years
I have connected servo motor but it doesn't moves. So to check i used multimeter and the voltage output i was getting for cycles was around 0.6V. Later i want to connect DC motors since this is what i have used for my driving wheels. But again DC motors will not function unless there is sufficient power from pwm output.

Since my arduino mega module is not functioning well, i am really helpless. I hope there is no connection issue becoz arduino mega is powered by my desktop usb port and so does the RR.

Please help me Steve coz m really stuck without this module....
Anonymous 6 years
Edwin,

Have you tried to also connect power to the Arduino? Normally when you drive servos from the Mega or Ardiuno it is recommended to attach an external power supply to help drive the system.

If you are seeing a change (even at 0.6V) then most likely not enough power is getting into the system.

Or can you verify using a direct Arduino program that it can drive the voltage higher given your current configuration?

STeven.
Anonymous 6 years
Hi
Do you mean external power to servos or to Arduino? At the moment i am supplying 6v to my servos and only pwm pin is connected to Arduino Mega.

When i generated pwm from my arduino sketch it works absolutely fine but i am only having problems with RR Arduino Mega GUI. Even when i move the sliders for pwm, no movement to the servos.

So this is whats happening with my setup.
Anonymous 6 years
i have just tried by connecting external power supply to arduino mega of 6V and just using the mega module gui to test. I am getting full 5V on digital pins when i activate and deactivate the checkerbox but still up to 0.6V on my pwm pins....no changes...am i doing anything wrong here? Any setup diagram will be useful for reference.
Anonymous 6 years
Ok, we have verified that 0.60 V is CORRECT on the mega. If you will note that when you move it all the other way you will get around 0.15V and NOT a negative voltage ... or zero. This has to do with the PWM signal. It will not be full voltage since it is not a solid stable signal. Our servos move fine with this 0.6V configuration. So something else is going on here.

Can you verify that you see more than 0.6V when you test it with the sketch that you say works?

When you move the sliders does the voltage change at all or does it stay constantly on a certain value?

Have you checked more than one pin for this behavior? We tested D5 and D4 which seem to work.

You may also try taking the power from the Arduino for the + and - for the servo. Do your servos hold their position or can you rotate them? If you can rotate them easily then they are probably not powered correctly.

This assumes you are testing servos and not DC motors. You need a motor controller board to control DC motors unless they require very little mAh.

STeven.
Anonymous 6 years
Now we are going in the same direction. When i move the sliders, i get the same results as yours, high and then low voltage. But i am trying this out with my motor controllers now since the wheels of my robot are driven by DC motors and this much pwm output isn't sufficient to even drive the motor controllers. How can we solve this. Its Simple H from robot power and the motor controller is powered by 12V battery.

Can you advise on this please since many hobbyists are using DC motors for control rather then servos.  
Anonymous 6 years
This is the sketch which i am using to directly test pwm output.
I am getting higher voltage than 0.6V. At pwm of 100, i am getting 1.9V and at 255, i am getting full 5V. This drives my motors without any hiccups.


//This is Arduino Code
//Standard PWM DC control

int E1 = 4;    //Enable Right motor controller
int E2 = 8;    //Enable Left motor controller
int M1 = 10;   //Motor 1 Forward PWM
int M2 = 6;    //Motor 2 Forward PWM
int M3 = 9;    //Motor 1 Reverse PWM
int M4 = 5;    //Motor 2 Reverse PWM

void stop(void)                      //Stop
        {
          digitalWrite(M1,LOW);  
          digitalWrite(M2,LOW);
          digitalWrite(M3,LOW);  
          digitalWrite(M4,LOW);      
        }  
void advance(char a,char b)         //Move forward
        {
          analogWrite (M1,a);      //PWM Speed Control
          digitalWrite(E1,HIGH);    
          analogWrite (M4,b);    
          digitalWrite(E2,HIGH);
          delay(5000);
        }  
void back_off (char a,char b)          //Move backward
        {
          analogWrite (M2,a);
          digitalWrite(E1,HIGH);  
          analogWrite (M3,b);    
          digitalWrite(E2,HIGH);
          delay(5000);
}
void turn_L (char a,char b)             //Turn Left
        {
          analogWrite (M1,a);
          digitalWrite(E1,HIGH);    
          analogWrite (M2,b);    
          digitalWrite(E2,LOW);
          delay(500);
        }
void turn_R (char a,char b)             //Turn Right
        {
          analogWrite (M4,a);
          digitalWrite(E2,HIGH);    
          analogWrite (M1,b);    
          digitalWrite(E1,LOW);
          delay(500);
        }
void setup(void)
{
    int i;
    for(i=6;i<=9;i++)
    pinMode(i, OUTPUT);  
    Serial.begin(115200);      //Set Baud Rate
}
void loop(void)
{
     char val = Serial.read();
     if(val!=-1)
       {
          switch(val)
           {
             case 'f'://Move Forward
                     advance (100,100);   //PWM Speed Control
                     break;
             case 'b'://Move Backward
                     back_off (100,100);
                     break;
             case 'l'://Turn Left
                     turn_L (100,100);
                     break;      
             case 'r'://Turn Right
                     turn_R (100,100);
                     break;          
            }    
          delay(40);
       }
      else stop();  
}
Anonymous 6 years
Yea, you should have started with that. The PWM generated by the above is NOT servo PWM. This pwm is a simulated analog signal with a square wave which is NOT the same as true servo PWM. They are different.

PWM means it is being modulated (turned on and off) but the frequencies are all wrong. The specific freq is not defined by the term PWM.

Plus, you have the extra signal telling forward and reverse ... so there is no way this would work with the generic Arduino servo control signals.

This has nothing to do with the way the Mega or Arduino module works and is outside of the focus of RoboRealm ...

So in order to get this to work correctly you will have to ignore the servo signals and focus on the digital lines in the GUI interface. If you want to go this route we can add analog out (currently we support analog in only) so that you can emulate the above but from the PC.

BUT if you don't understand what the above code is doing you will not be able to emulate that from the PC side. You may want to get someone more familiar with Arduino programming to help you out.

You can also explore the MCU_Communicator module and perhaps integrate that Arduino code with what you have above.

Regardless of the route you have a bit of programming ahead of you.

STeven.
Anonymous 6 years
So are you saying that we cannot control motors using arduino mega module?
And we will have to use primitive method of using serial module where we need to know the hardcore  programming.

But it would be great if you can add analog out pins so that we can directly transfer analog write values. This will be really appreciated Steve.

Are there any other ways to go about it so that i can control my robot with ease without purchasing any new stuff. I have already bought motor controllers and DC motor coz initially i thot that motors can be controlled by this module.

I know others will be also eager to know this info.

Anywayz thanks alot.  
Anonymous 6 years
Both modules now support Analog out.

I have included a robofile that should make of the robot move forward but you will have to change the activation pins from 4 and 8 to 22 and 23 before this will work.

You may also find that the robot does not move forward but instead pivots. This is because the script that you included does not appear to use the pins correctly since the comments for the pins do not match the functionality.

Please note that you will have to download the most current version of RoboRealm in order for this to work.  You will also have to download and install the Arduino sketch again since this script has also changed.

STeven.
program.robo
Raj from Fiji  [9 posts] 6 years
Thank you Steven. You are a life saver.
Hope this will help others as well.

Thanks for your time.

This forum thread has been closed due to inactivity (more than 4 months) or number of replies (more than 50 messages). Please start a New Post and enter a new forum thread with the appropriate title.

 New Post   Forum Index