Go Down

Topic: robot arm 3 servo control problem (Read 3270 times) previous topic - next topic

adam21

Jan 13, 2014, 01:37 am Last Edit: Jan 13, 2014, 01:41 am by adam21 Reason: 1
i just try to control 3 servo engines. I send a data to first servo. i want to move only first but second and third engine work with it  too its not complete work but  2nd and 3rd servo engines just vibrating and try to move. How can i fix that problem ? could you help me  (Y)

//arduino code
Code: [Select]
#include <Servo.h>
Servo alt,kol,ust;
static int pos=0,apos=0,upos=0;

void setup()
{
 Serial.begin(9600);
 kol.attach(9);  // attaches the servo on pin 9 to the servo object
 alt.attach(3);
 ust.attach(6);
 
}
void loop()
{

if(Serial.available() > 0)
 {
   char gelen = Serial.read();
   
   if(gelen == 'a')
   {
     while(Serial.available() <1)
           ; // wait for a character
     pos=0;
     do{
        gelen = Serial.read();    
       if(gelen >= '0' && gelen <= '9')              // is ch a number?  
         pos = pos * 10 + gelen - '0';           // yes, accumulate the value
     
   }
     while(gelen != 'b');
     kol.write(pos);
     pos = 0;

     
   }
   
   else if(gelen == 'c')
   {
     while(Serial.available() <1)
           ; // wait for a character
     apos=0;
     do{
        gelen = Serial.read();    
       if(gelen >= '0' && gelen <= '9')            
         apos = apos * 10 + gelen - '0';
         
     }
     while(gelen != 'd');
     alt.write(apos);
     apos = 0;
     
     
     }
   
   else
   {
     while(Serial.available() <1)
           ; // wait for a character
     upos=0;
     do{
        gelen = Serial.read();    
       if(gelen >= '0' && gelen <= '9')            
         upos = upos * 10 + gelen - '0';
           
     }
     while(gelen != 'f');
     ust.write(upos);
     upos = 0;
     
   }
   }

 }






c# code


Code: [Select]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;
using System.Threading;

namespace WindowsFormsApplication1
{
   public partial class Form1 : Form
   {
       public Form1()
       {
           InitializeComponent();
           serialPort1.PortName = "COM4";
           serialPort1.BaudRate = 9600;

           
           
       
       }

       private void Form1_Load(object sender, EventArgs e)
       {

           
       }

       private void trackBar1_Scroll(object sender, EventArgs e)
       {
           serialPort1.Open();
           label1.Text = trackBar1.Value.ToString();
           serialPort1.Write("e");
           serialPort1.Write(trackBar1.Value.ToString());
           serialPort1.Write("f");
           serialPort1.Close();
   
       }

       private void trackBar2_Scroll(object sender, EventArgs e)
       {
           serialPort1.Open();
           label2.Text = trackBar2.Value.ToString();
           serialPort1.Write("c");
           serialPort1.Write(trackBar2.Value.ToString());
           serialPort1.Write("d");
           serialPort1.Close();
           
       }

       private void trackBar3_Scroll(object sender, EventArgs e)
       {
           serialPort1.Open();
           label3.Text = trackBar3.Value.ToString();
           serialPort1.Write("a");
           serialPort1.Write(trackBar3.Value.ToString());
           serialPort1.Write("b");
           serialPort1.Close();
           
       }

     

     
   }
}







PaulS

#1
Jan 13, 2014, 01:42 am Last Edit: Jan 13, 2014, 01:45 am by PaulS Reason: 1
Code: [Select]
 kol.attach(9);  // attaches the servo on pin 9 to the servo object
 alt.attach(3);
 ust.attach(6);

It is not necessary to attach the servos to PWM pins.

It is necessary, though, to tell us how the servos are powered.

Code: [Select]
     do{
        gelen = Serial.read();    
       if(gelen >= '0' && gelen <= '9')              // is ch a number?  
         pos = pos * 10 + gelen - '0';           // yes, accumulate the value
     
   }
     while(gelen != 'b');

It's advisable to wait for serial data to arrive.

What is sending the serial data?
Edit: Never mind. I see that you have a C# application mishandling the communication. Are you aware that opening the serial port resets the Arduino? Are you aware that closing the serial port resets the Arduino? You should be. You should re-write your C# application so that happens ONCE each, not every time you want to send data.
The art of getting good answers lies in asking good questions.

adam21

new aplication still problem.






Code: [Select]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;
using System.Threading;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            serialPort1.PortName = "COM4";
            serialPort1.BaudRate = 9600;
            serialPort1.Open();
           
           
         
        }

        private void Form1_Load(object sender, EventArgs e)
        {

           
        }

        private void trackBar1_Scroll(object sender, EventArgs e)
        {
           
            label1.Text = trackBar1.Value.ToString();
            serialPort1.Write("e");
            serialPort1.Write(trackBar1.Value.ToString());
            serialPort1.Write("f");
           
   
        }

        private void trackBar2_Scroll(object sender, EventArgs e)
        {
           
            label2.Text = trackBar2.Value.ToString();
            serialPort1.Write("c");
            serialPort1.Write(trackBar2.Value.ToString());
            serialPort1.Write("d");
           
           
        }

        private void trackBar3_Scroll(object sender, EventArgs e)
        {
           
            label3.Text = trackBar3.Value.ToString();
            serialPort1.Write("a");
            serialPort1.Write(trackBar3.Value.ToString());
            serialPort1.Write("b");
           
           
        }

       

       
    }
}

michinyon

Your logic seems rather incomprehensible,   but the most likely reason for your problem,   is inadequate power supply for the servos.

zoomkat

Don't power servos directly from the arduino. Below is a typical way to power servos.

Google forum search: Use Google Search box in upper right side of this page.
Why I like my 2005 Rio Yellow Honda S2000  https://www.youtube.com/watch?v=pWjMvrkUqX0

megaBlocks

what kind of cabling are you using? how long are your signal wires? and what make/model are those servos??

Robin2

I don't have the appetite for studying long lengths of code but the semi-colon on the first line of this looks suspicious (from your original post)

   
Code: [Select]
while(gelen != 'd');
      alt.write(apos);
      apos = 0;


Also it looks like there are opening curly brackets without matching closing brackets.

Plus (of course) the other comments about how things are wired up.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.


PaulS

Quote
there is no problem with 2 engines but there is problem with 3 engines.

But you are not going to tell us how they are wired. Well, we are not going to tell you how to solve your problem, then, either.
The art of getting good answers lies in asking good questions.

megaBlocks

You say that you can only get two of them to run simultaneously, and when a third is added the 2nd and 3rd start to shiver??

are you referring to both of the MG946R servos start shivering? or the SG-90 and one of the MG946Rs?

also i see they are rated from 4.8 to 7.2 Vin.
so have you tried:
trimming your servo input voltage to 4.9v and test.
trimming your servo input voltage to 5.1v and test.
does that make any difference??

I found with some servos that the signal's amplitude is somewhat dependent on the input voltage.

one thing to try is maybe adding some hefty sized caps across your positive and negative rails.

but what are you using to power these servos (a variable bench PS, wall transformer, LDO)???

and a few questions about whats in your toolbox:

Do you have access to an oscilloscope of any kind??

and most importantly, do you have a DMM handy???

Best of luck!!!

Go Up