Can't control AX-12 servo position with Smart Servo Shield

I’m new to arduino programing. I able to make http://www.dfrobot.com/index.php?route=product/product&product_id=958&search=smart+servo+shield&description=true Smart Servo Shield for Arduino + Ax-12A servos work for me in “continous (rotation) mode”, but I’m unable to control servo position in “servo mode”. The problem is that I can only control servo velocity and when I change values for servo position, the servo start rotating CCW with defined velocity

That’s the code to control servo position in “servo mode”

/*
 # This Sample code is for testing the Digital Servo Shield.
  
 # Editor : Phoebe
 # Date   : 2013.5.17
 # Ver    : 0.1
 # Product: Digital Servo Shield for Arduino
 # SKU    : 
   
 # Hardwares:
 1. Arduino UNO
 2. Digital Servo Shield for Arduino
 3. Digital Servos( Compatible with AX-12,CDS55xx...etc)
 4. Power supply:6.5 - 12V 
  
 */

#include <SPI.h>
#include <ServoCds55.h>
#include "pins_arduino.h"
ServoCds55 myservo;

void setup (void)
{
  Serial.begin (115200);
  digitalWrite(SS, HIGH);  
  SPI.begin ();
  SPI.setClockDivider(SPI_CLOCK_DIV8);
} 

void loop (void)
{

        myservo.setVelocity(100);// set velocity to 100(range:0-300) in Servo mode

        myservo.write(1,300);//ID:1  Pos:300
        delay(3000);
        myservo.write(,0);//ID:1  Pos:0


       
   
}

ServoCds55.cpp

/*
ServoCds55.cpp - Library for Digital Servo Driver Shield
May 15th, 2013
Version 0.1
*/

#include "ServoCds55.h"
#include "Arduino.h"
#include "SPI.h"

ServoCds55::ServoCds55 (){
	velocity_temp = 150;
	upperLimit_temp = 300;
}

byte ServoCds55::transferAndWait (const byte what)

{
  byte a = SPI.transfer (what);
  delayMicroseconds (20);
  return a;
} 

void ServoCds55::setVelocity(int velocity){   //set servo velocity
  velocity_temp = velocity;
}

void ServoCds55::setPoslimit(int posLimit){  // set servo pos limit
  upperLimit_temp =  posLimit;
}

void ServoCds55::write(int ID,int Pos){     //  Servo Mode
  SetServoLimit(ID,upperLimit_temp);
  WritePos(ID,Pos);// default velocity:150 
}

void ServoCds55::WritePos(int ID,int Pos){ 

  int PosB = (Pos>>8 & 0xff);//low
  int PosS = (Pos & 0xff);//high
  int velocityB = (velocity_temp>>8 & 0xff);
  int velocityS = (velocity_temp & 0xff);
  digitalWrite(SS, LOW);    
  transferAndWait (ID); 
  transferAndWait (PosB);
  transferAndWait (PosS);
  transferAndWait (velocityB);
  transferAndWait (velocityS);
  digitalWrite(SS, HIGH);
  delay(10);
}  

void ServoCds55::SetServoLimit(int ID,int upperLimit_temp){

  int upperLimitB = (upperLimit_temp>>8 & 0xff);
  int upperLimitS =  (upperLimit_temp & 0xff);
  digitalWrite(SS, LOW);    
  transferAndWait (ID);
  transferAndWait (upperLimitB);
  transferAndWait (upperLimitS);
  digitalWrite(SS, HIGH);
  delay(10);

}

ServoCds55.h

/*
ServoCds55.h - Library for Digital Servo Driver Shield
May 15th, 2013
Version 0.1
*/


#ifndef ServoCds55_H
#define ServoCds55_H

#include "Arduino.h"


class ServoCds55{
public:
	ServoCds55();
    void WritePos(int ID,int Pos);
    void write(int ID,int Pos);
    void setVelocity(int velocity);
    void setPoslimit(int posLimit);
    void SetServoLimit(int ID,int upperLimit);

	byte transferAndWait (const byte what);

private:

    int velocity_temp;
    int upperLimit_temp;

};

#endif

Any ideas ?

Do you have a servo? Or do you have a variable speed, reversible, electric motor? They are not interchangeable. If you have a servo, you can't make it rotate continuously. If you have a variable speed, reversible, electric motor (sold by some morons under the name continuous rotation servo) you can't make it go to a position and stop.

I have Dynamixel AX-12A servos, I can control them in continuous rotation mode only, I can change velocity, direction, and id’s of servos. But i can’t use them as normal servos (Control position in deg) because they start rotating counter clockwise. And I’m sure thta’s something wrong with the code. I’m beginner with arduino programming and I can’t identify the problem. that’s why I’m asking for help

But i can't use them as normal servos

Correct. They are NOT normal servos.

And I'm sure thta's something wrong with the code.

And I'm equally certain that is NOT a code problem. If you wanted a real servo, you should have bought a real servo.

So if you are sure that's NOT a code problem can you please explain me what the problem is?

can you please explain me what the problem is?

Sure. The problem is that you can't use an elephant as a riot control gun.

When you bought that thing, you were lied to. It is a variable speed, reversible, electric motor. It is NOT a servo.

If you can't or don't want to help me please stop posting your pointless comments. I expect people help not criticism

jedrzejgalecki: If you can't or don't want to help me please stop posting your pointless comments. I expect people help not criticism

Just because you don't like the answers does not make them wrong. It is your attitude that needs adjustment.

You right , your comments are not wrong they are just completely irrelevant and useless for me. I assume that you don’t know the answer. Stop wasting my time

I assume that you don't know the answer. Stop wasting my time

I do know the answer. I've told you the answer. You just won't accept that you can't make a silk purse out of a sow's ear. Get over it, and quit wasting our time.

If you know the answer can you use technical language not metaphors? I'm new to arduino and programming and not really sure what you mean by "you can't use an elephant as a riot control gun."

If you know the answer can you use technical language not metaphors?

I have. You didn’t understand, or didn’t like the answer. So, I tried a different approach.

A servo is a variable speed, reversible, electric motor with limits and position encoders, so that it can go to a specified position and stop.

A continuous rotation “servo” is a regular servo that has been modified. The limits have been removed, along with the position encoders. It is, therefore, technically no longer a servo, and anyone that says it is is wrong.

What you have is a piece of hardware that is missing stuff needed to be a servo.

You can’t make something that is not a servo behave like a servo.

Thank you very much, now it's much simpler :) From what I know and what I've seen (forums and YouTube ) it' s possible to control position of dynamical actuators both ways (continuous rotation and like"servo") The code I've attached is the part of the official library (responsible for "servo "mode) for the Smart Servo Shield I've bought. The rest of the code to use AX-12A in continuous mode work well for me the same with code to change and reset ID,s.

The range in "servo" mode is from 0 to 300 deg in 1024 steps , min control angle is 0.29 deg. http://robosavvy.com/store/product_info.php/products_id/1435

Do the Ax-12 servos use the conventional servo control commands?

Hi jedrzejgalecki, I recently buy the "Smart Servo Shield" one week agoo . This one => http://www.dfrobot.com/index.php?route=product/product&product_id=958 And follow the insctruction about how to plug and use the sample code DFRobot give but don't work ..

I think i will become crazy. Me too i can't use my Dynamixel AX-12A

DFRobot said , this is full compatible with Dynamixel AX/MX series servos. But i can not make work my servos =(

So , are you finally find a solution on your problem ? Cause it's look same as me

Thank you a lot

This is how i plug the shield and the servo on my arduino mega 2560:

I hope somebody can find the problem :~

https://imageshack.com/i/iqIajjOoj

The library refers to the SPI slave select as SS. In pins-arduino.h for the Mega, that is D53. The schematic shows the slave select (SS) using D10.

It appears your choices are to modify the library or jumper D10 on the shield to D53 on the Mega.

Woo so nice !
Thanks a lot for this quickly answer.
So, you mean this code line:

digitalWrite(SS, HIGH);

is belong to an arduino UNO and not for a arduino MEGA ?
That why this code doesn’t work .
The only solution is to modify the library ? When you mean jumper D10 on the shield to D53 on the Mega , you mean connect the D10 on the shield to D53 on the Mega ? how can i do that ?
Thank again my friend. i’m exiting to finally approach the solution

I attached what I think will use D10 as the slave select. You must set D10 to OUTPUT and HIGH before using the library.

void setup() {
    pinMode(10,OUTPUT);
    digitalWrite(10, HIGH);

    // rest of your setup

The only thing I changed in the library was replaced “SS” with “10” in the digitalWrite() calls.

ServoCds55.cpp (2.73 KB)

@SurferTym you are so nice !

Thank again , thank a looot for everything