robotic arm problem help me please (4dof)

void handle_nled();
void handle_duoji();              //声明舵机处理函数
void handle_uart1();              //声明串口处理函数
void handle_ps2();                //声明PS2处理函数
void handle_warning(void);        //声明低压报警函数
void dida(u8 times, u8 frequency);//声明滴答函数
void handle_auto_group(void);      
void setup() {
    pinMode(BEEP_PIN, OUTPUT);
    pinMode(NLED_PIN, OUTPUT);
    pinMode(IN1, OUTPUT);
    pinMode(IN2, OUTPUT);
    pinMode(IN3, OUTPUT);
    pinMode(IN4, OUTPUT);
    Serial.begin(115200 ); 
    ps2x.config_gamepad(PS2_CLK, PS2_CMD, PS2_ATT, PS2_DAT, true, true);//配置PS2手柄
    type = ps2x.readType();//返回PS2类型
     switch(type) {
       case 0:
        Serial.println("Unknown Controller type");
       break;
       case 1:
        Serial.println("DualShock Controller Found");
       break;
       case 2:
         Serial.println("GuitarHero Controller Found");
       break;
     }
    for(byte i = 0; i < DJ_NUM; i++) {//循环使相应的舵机伺服对象连接到对应的引脚
        myservo[i].attach(duoji_pin[i]); 
        }
    for(byte i = 0; i < DJ_NUM; i++) {
        myservo[i].writeMicroseconds(duoji_doing[i].aim);//循环写入初始PWM目标值 
    }
    dida(3, 50);
    Motor_Stop();
    delay(1000);
}

the Motor_Stop() is the error. i just searched it in the internet and please help me. or if someone knows how to code a 4dof robotic arm. please help

Your other post on the same subject has been deleted

What error?

I'd say the problem is that Motor_Stop() isn't defined anywhere. It might be defined in the rest of the program that you haven't posted but I can't help with things I can't see.

Post the COMPLETE program and the ACTUAL error report.

Steve

it says motor_stop was not declared in this scope

ps2_bt.ino (5.93 KB)

hi! the first attached code is having that error but this second attachment will only create jitter on my robotic arm. the code has no error in compiling but it only jitter my robotic arm. please check my code please if there is any error why my robotic arm won't function as what it says :frowning:

#include <Adafruit_PWMServoDriver.h>
#include <Wire.h>
#define SERVOMIN 150 // this is the 'minimum' pulse length count (out of 4096)
#define SERVOMAX 600 // this is the 'maximum' pulse length count (out of 4096)

// called this way, it uses the default address 0x40
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
// you can also call it with a different address you want
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x41);
// you can also call it with a different address and I2C interface
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(&Wire, 0x40);

// Depending on your servo make, the pulse width min and max may vary, you 
// want these to be as small/large as possible without hitting the hard stop
// for max range. You'll have to tweak them as necessary to match the servos you

uint8_t servo1 = 0, servo2 = 1, servo3 = 2, servo4 = 3; // Servo pin number
int potpin1 = A0,potpin2 = A1,potpin3 = A2,potpin4 = A3; // analog pin used to connect the potentiometer
int val1,val2,val3,val4; // variable to read the value from the analog pin

void setup() {
   Serial.begin(9600);

  pwm.begin();
  
  pwm.setPWMFreq(60);  // Analog servos run at ~60 Hz updates

  delay(10);
  

}

void loop() {

 val1 = analogRead(potpin1);
 val1 = map(val1,0,1023,0,180);
 pwm.setPWM(servo1,0,val1);
 Serial.println(val1);
 delay(15);
 
 val2 = analogRead(potpin2);
 val2 = map(val2,0,1023,0,180);
 pwm.setPWM(servo2,0,val2);
 Serial.println(val2);
 delay(15);
 
 val3 = analogRead(potpin3);
 val3 = map(val3,0,1023,0,180);
 pwm.setPWM(servo3,0,val3);
 Serial.println(val3);
 delay(15);
 
 val4 = analogRead(potpin4);
 val4 = map(val4,0,1023,70,150);
 pwm.setPWM(servo4,0,val4);
 Serial.println(val4);
 delay(15);
 
}

Hi prosi,

your code attached to post #5 uses a library Adafruit_PWMServoDriver.h

this will only work if you have a compatible I2C-Servodriver-board.
Then some things deviate from the example code
which can be found here

compared to this example these lines are missing

#define USMIN  600 // This is the rounded 'minimum' microsecond length based on the minimum pulse of 150
#define USMAX  2400 // This is the rounded 'maximum' microsecond length based on the maximum pulse of 600
#define SERVO_FREQ 50 // Analog servos run at ~50 Hz updates

standard RC-servos are working at a frequency of 50Hz
You define 60 Hz here

  pwm.setPWMFreq(60);  // Analog servos run at ~60 Hz updates

Wherever your code comes from I guess the author did not really know about the specs
and how to use the servocontroller properly

so try the original demo-code

If you do not have such an adafruit I2C-servo-controller-board you need a complete library
So please describe what hardware you are using exact type
it might be a problem of disconnected GND between the Arduino and your extra-powersupply for the servos.
If you try to power the servos from an Arduino-board. The onboard voltage-regulator is way too small to deliver the needed current

So it is really nescessary to describe your hardware in detail.
The microcontroller-world is not superstandardised like USB-devices. You have to take care of more details than just

"does the plug fit into the socket?"

You have to

  • analyse datasheets and
  • check if voltages are compatible

gain some basic knowledge about electronics and having a digital multimeter will be very useful

best regards Stefan

 val1 = map(val1,0,1023,0,180);

You are writing values between 0 and 180 to the servos. But at the top of the program you set the range of values as minimum 150, maximum 600. Try changing your map() statements to use those values instead of 0, 180. There may be other problems but that's one obvious one so fix that and try again.

Steve

StefanL38:
Hi prosi,

your code attached to post #5 uses a library Adafruit_PWMServoDriver.h

this will only work if you have a compatible I2C-Servodriver-board.
Then some things deviate from the example code
which can be found here
Adafruit-PWM-Servo-Driver-Library/servo.ino at master · adafruit/Adafruit-PWM-Servo-Driver-Library · GitHub

compared to this example these lines are missing

#define USMIN  600 // This is the rounded 'minimum' microsecond length based on the minimum pulse of 150

#define USMAX  2400 // This is the rounded 'maximum' microsecond length based on the maximum pulse of 600
#define SERVO_FREQ 50 // Analog servos run at ~50 Hz updates



standard RC-servos are working at a frequency of 50Hz
You define 60 Hz here


pwm.setPWMFreq(60);  // Analog servos run at ~60 Hz updates



Wherever your code comes from I guess the author did not really know about the specs
and how to use the servocontroller properly

so try the original demo-code

If you do not have such an adafruit I2C-servo-controller-board you need a complete library
So please describe what hardware you are using exact type 
it might be a problem of disconnected GND between the Arduino and your extra-powersupply for the servos.
If you try to power the servos from an Arduino-board. The onboard voltage-regulator is way too small to deliver the needed current

So it is really nescessary to describe your hardware in detail.
The microcontroller-world is **not** superstandardised like USB-devices. You have to take care of more details than just 

"does the plug fit into the socket?"

You have to 
- analyse datasheets and 
- check if voltages are compatible 

gain some basic knowledge about electronics and having a digital multimeter will be very useful

best regards Stefan

Arduino Uno with Micro USB cable
5V Power Adapter
Breadboard
Jumper Wires
16x12-bit PWM/Servo Shield
10K Potentiometer (4 pieces)
that is the materials i used. should i just add the 3 define codes you listed and remove the pwm code on mine? should i give that a try or what? i'm sorry i am still a newbie in robotics

should i just used the code you have given me and give it a try? i tried using the minimum and maximum and still won't work as programmed. should i add the 3 define codes and remove the pwm in my code?

Yes! If you have hardware first thing is to test the hardware with a program that is known for well functioning.

There are so many different servoshields on the market that need different signals to control them.

It is essential that you post the exact type and even better a datasheet and/or usermanual of your servoshield.

You mentioned a 5V power-supply. Is the +5V of the powersupply directly connected to the shield?
Did you connect the Ground of the servoshield with the ground of the arduino?
Please take pictures of your hardware from vertical above so that it is very easy to see what is connected to what.
After taking the picture take a careful look at the pictures and check:
is somebody who has just this pictures and not the real thing able to see what is connected to what?

It is much better to add more pictures than making your potential users ask back for more pictures.
More pictures are entertaining having to ask back is annoying

best regards Stefan

StefanL38:
Yes! If you have hardware first thing is to test the hardware with a program that is known for well functioning.

There are so many different servoshields on the market that need different signals to control them.

It is essential that you post the exact type and even better a datasheet and/or usermanual of your servoshield.

You mentioned a 5V power-supply. Is the +5V of the powersupply directly connected to the shield?
Did you connect the Ground of the servoshield with the ground of the arduino?
Please take pictures of your hardware from vertical above so that it is very easy to see what is connected to what.
After taking the picture take a careful look at the pictures and check:
is somebody who has just this pictures and not the real thing able to see what is connected to what?

It is much better to add more pictures than making your potential users ask back for more pictures.
More pictures are entertaining having to ask back is annoying

best regards Stefan

sir i tried the code and it's not jittering now but it won't move. i tried to attached pictures but it says to large entity :frowning: is there any way i can send pictures?

this is the pictures sir.

pictures.zip (671 KB)

slipstick:

 val1 = map(val1,0,1023,0,180);

You are writing values between 0 and 180 to the servos. But at the top of the program you set the range of values as minimum 150, maximum 600. Try changing your map() statements to use those values instead of 0, 180. There may be other problems but that's one obvious one so fix that and try again.

Steve

sir this is the new program. it's not jittering now but it's not moving

#include <Adafruit_PWMServoDriver.h>
#include <Wire.h>
#define SERVOMIN 150 // this is the 'minimum' pulse length count (out of 4096)
#define SERVOMAX 600 // this is the 'maximum' pulse length count (out of 4096)
#define USMIN 600 
#define USMAX 2400
#define SERVO_FREQ 50
// called this way, it uses the default address 0x40
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
// you can also call it with a different address you want
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x41);
// you can also call it with a different address and I2C interface
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(&Wire, 0x40);

// Depending on your servo make, the pulse width min and max may vary, you 
// want these to be as small/large as possible without hitting the hard stop
// for max range. You'll have to tweak them as necessary to match the servos you

uint8_t servo1 = 0, servo2 = 1, servo3 = 2, servo4 = 3; // Servo pin number
int potpin1 = A0,potpin2 = A1,potpin3 = A2,potpin4 = A3; // analog pin used to connect the potentiometer
int val1,val2,val3,val4; // variable to read the value from the analog pin

void setup() {
   Serial.begin(9600);

  pwm.begin();
  

  delay(10);
  

}

void loop() {

 val1 = analogRead(potpin1);
 val1 = map(val1,0,1023,SERVOMIN,SERVOMAX);
 pwm.setPWM(servo1,0,val1);
 Serial.println(val1);
 delay(15);
 
 val2 = analogRead(potpin2);
 val2 = map(val2,0,1023,SERVOMIN,SERVOMAX);
 pwm.setPWM(servo2,0,val2);
 Serial.println(val2);
 delay(15);
 
 val3 = analogRead(potpin3);
 val3 = map(val3,0,1023,SERVOMIN,SERVOMAX);
 pwm.setPWM(servo3,0,val3);
 Serial.println(val3);
 delay(15);
 
 val4 = analogRead(potpin4);
 val4 = map(val4,0,1023,SERVOMIN,SERVOMAX);
 pwm.setPWM(servo4,0,val4);
 Serial.println(val4);
 delay(15);
 
}

prosdei12:
this is the pictures sir.

Please make the pictures visible in your Post. People don't like downloading ZIP files from unknown sources.

See this Simple Image Posting Guide

...R

Robin2:
Please make the pictures visible in your Post. People don't like downloading ZIP files from unknown sources.

See this Simple Image Posting Guide

...R

the pictures sir

Hi prosi,

do you know the meaning of the words pictures taken from vertical above?

If you want really help you should do all the work that can be done by YOU.
This is:

posting a link to the datasheet / usermanual of the servo-shield
How should I check if everything is wired correctly without looking into the datasheet???

taking pictures from vertical above
How should I see for sure by looking from a 45-degree-angle if you plugged in the wires correctly?

not possible!

you are starting to erode my patience to help you.
You should really do it the way I have asked for

best regards Stefan

What is the Arduino that you are using? And have you tried to run the "servo" example program that comes with the Adafruit library? What results do you get with that?

Also where did you get that shield from? It doesn't look like a genuine Adafruit shield.

Steve

prosdei12:
the pictures sir

Photos of your hardware are rarely useful - I would certainly have no confidence that I could detect correct or incorrect wiring from such photos.

Just make a simple pencil drawing showing how everything is connected and post a photo of the drawing.

And, as in Reply #15, post a link to the datasheet for the shield.

...R

i'm really sorry sir. please don't be mad at me and please still help me
i have no user manual of the servo shield but when i look it is MG90S micro servo and i use this
16-Channel 12-bit PWM/Servo Shield 16 channel Servo drive module

the left servo is connected in 0
the right servo is connected in 1
the claw is connected in 2
the base is connected in 3

the first potentiometer is in Analog 0
the second potentiometer is in Analog 1
the third potentiometer is in Analog 2
the last potentiometer is in Analog3

another picture sir. please have more patience with me