SCS 15 Servo, Library and how it works

Hello,

I am a new user of Arduino. I am working on a project with a robotic mechanism with 5+ servos. One of them is an SCS 15 Feetech servo motor. I have found (after a long searching) the library SCServo.h which is needed to control the servo from Arduino UNO and I have connected it via a TT Linker as shown in many pictures in web. I currently look how the library works and I can't find out. I have place a code (as shown below) but servo doesn't move. Is there anyone who knows how this library works or she/he has used a same motor through arduino in order to guide me?

It would be glad to find someone who knows how it is done. Thank you very much in advance!

Arduino Code:

#include <SCServo.h>
SCServo SERVO;
void setup()
{
Serial.begin(1000000);//init Serial baudrate
delay(500);
SERVO.EnableTorque(0xfe,1);
}
void loop()
{
u16 i;
for(i = 0;i < 1024; i++)
{
SERVO.WritePos(0xfe,i,100);//All Servo(broadcast) rotate to the position:i
delay(10);
}
for(i = 1024; i > 0; i–)
{
SERVO.WritePos(0xfe,i,100);//All Servo(broadcast) rotate to the position:i
delay(10);
}
}

Please use code tags (</> button on the toolbar) when you post code or warning/error messages. The reason is that the forum software can interpret parts of your code as markup, leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier to read your code and to copy it to the IDE or editor. Using code tags and other important information is explained in the How to use this forum post. Please read it.

Please always do a Tools > Auto Format on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read.

Hi, everybody. I found a widget. Can anyone tell me how to use it?

OP: That is what your post looks like. If you need help with a library, POST A LINK TO IT.

Sorry for mistakes, I am a new user and I am desperate with this servo so I even forgot to read about posting in here.

Sorry once more! Hope to get some help over this project!

PaulS:
Hi, everybody. I found a widget. Can anyone tell me how to use it?

OP: That is what your post looks like. If you need help with a library, POST A LINK TO IT.

Can you please further explain me how I can do this? I am really a newbie and I don't understand what you mean.

Thank you very much

Where did you get the library? That is what we need to know.

Normaly there should be a link for download in reservozone.com (but site doesn't work for long now). So I searched and found the .h and .cpp files seperately (I don't remember where did I find them, it is weeks ago). I can upload the files here if this may help further.

Thank you very much!

I can upload the files here if this may help further.

It wouldn't hurt. Providing help without them seems unlikely.

Ok,

Below is the SCServo.h file:

/*
 * SCServo.h
 * Series Control Servo
 * Created on: 2014.4.15
 * Author: Tony tan
 */
#ifndef _SCSERVO_h_
#define _SCSERVO_h_

#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif

#define		s8		char
#define		u8		unsigned char
#define		u16		unsigned short
#define		s16		short
#define		u32		unsigned long
#define		s32		long

class SCServo{
	public:
		SCServo();
		u8 EnableTorque(u8 ID, u8 Enable, u8 ReturnLevel=2);
		u8 WritePos(u8 ID, int position, int velocity, u8 ReturnLevel=2);
		u8 RegWritePos(u8 ID, int position, int velocity, u8 ReturnLevel=2);
		s16 ReadPos(u8 ID);
		void RegWriteAction();
		void SyncWritePos(u8 ID[], u8 IDN, int position, int velocity);
	private:
		u8 ReadBuf(u8 len, u8 *buf=NULL);
		#define		startByte	0xFF
		#define		TIMEOUT		600//TIMEOUT 600
	//register Address
		#define P_MODEL_NUMBER_L 0
		#define P_MODEL_NUMBER_H 1
		#define P_VERSION_L 3		
		#define P_VERSION_H 4
		#define P_ID 5
		#define P_BAUD_RATE 6
		#define P_RETURN_DELAY_TIME 7
		#define P_RETURN_LEVEL 8
		#define P_MIN_ANGLE_LIMIT_L 9
		#define P_MIN_ANGLE_LIMIT_H 10
		#define P_MAX_ANGLE_LIMIT_L 11
		#define P_MAX_ANGLE_LIMIT_H 12
		#define P_LIMIT_TEMPERATURE 13
		#define P_MAX_LIMIT_VOLTAGE 14
		#define P_MIN_LIMIT_VOLTAGE 15
		#define P_MAX_TORQUE_L 16
		#define P_MAX_TORQUE_H 17
		#define P_ALARM_LED 18
		#define P_ALARM_SHUTDOWN 19
		#define P_COMPLIANCE_P 21
		#define P_COMPLIANCE_D 22
		#define P_COMPLIANCE_I 23
		#define P_PUNCH_H 24
		#define P_PUNCH_L 25
		#define P_CW_COMPLIANCE_MARGIN 26
		#define P_CCW_COMPLIANCE_MARGIN 27

		#define P_TORQUE_ENABLE (31)
		#define P_LED (32)
		#define P_GOAL_POSITION_L (33)
		#define P_GOAL_POSITION_H (34)
		#define P_GOAL_SPEED_L (35)
		#define P_GOAL_SPEED_H (36)
		#define P_LOCK (37)

		#define P_PRESENT_POSITION_L (41)
		#define P_PRESENT_POSITION_H (42)
		#define P_PRESENT_SPEED_L (43)
		#define P_PRESENT_SPEED_H (44)
		#define P_PRESENT_LOAD_L (45)
		#define P_PRESENT_LOAD_H (46)
		#define P_PRESENT_VOLTAGE (47)
		#define P_PRESENT_TEMPERATURE (48)
		#define P_REGISTERED_INSTRUCTION (49)
		#define P_ERROR (50)
		#define P_MOVING (51)
	
	//Instruction:
		#define INST_PING 0x01
		#define INST_READ 0x02
		#define INST_WRITE 0x03
		#define INST_REG_WRITE 0x04
		#define INST_ACTION 0x05
		#define INST_RESET 0x06	
		#define INST_SYNC_WRITE 0x83
};
#endif

and here is SCServo.cpp file:

/*
 * SCServo.cpp
 * Series Control Servo
 * Created on: 2014.4.15
 * Author: Tony tan
 */
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#define printf(args) (Serial.write(args))
#else
#include "WProgram.h"
#define printf(args) (Serial.print(args,BYTE))
#endif
#include "SCServo.h"

SCServo::SCServo ()
{
}

u8 SCServo::EnableTorque(u8 ID, u8 Enable, u8 ReturnLevel)
{
	int messageLength = 4;

	printf(startByte);
	printf(startByte);
	printf(ID);
	printf(messageLength);
	printf(INST_WRITE);
	printf(P_TORQUE_ENABLE);
	printf(Enable);
	printf((~(ID + messageLength + INST_WRITE + Enable + P_TORQUE_ENABLE))&0xFF);
	if(ID != 0xfe && ReturnLevel==2)
		return ReadBuf(6);
	return 6;
}

u8 SCServo:: WritePos(u8 ID, int position, int velocity, u8 ReturnLevel)
{
	int messageLength = 7;
	byte posL =  position>>8;
	byte posH =  position&0xff;	
	byte velL =  velocity>>8;
	byte velH =  velocity&0xff;

	printf(startByte);
	printf(startByte);
	printf(ID);
	printf(messageLength);
	printf(INST_WRITE);
	printf(P_GOAL_POSITION_L);
	printf(posL);
	printf(posH);
	printf(velL);
	printf(velH);
	printf((~(ID + messageLength + INST_WRITE + P_GOAL_POSITION_L + posL + posH + velL + velH))&0xFF);
	if(ID != 0xfe && ReturnLevel==2)
		return ReadBuf(6);
	return 6;
}

u8 SCServo:: RegWritePos(u8 ID, int position, int velocity, u8 ReturnLevel)
{
	int messageLength = 7;
	byte posL =  position>>8;
	byte posH =  position&0xff;		
	
	byte velL =  velocity>>8;
	byte velH =  velocity&0xff;

	printf(startByte);
	printf(startByte);
	printf(ID);
	printf(messageLength);
	printf(INST_REG_WRITE);
	printf(P_GOAL_POSITION_L);
	printf(posL);
	printf(posH);
	printf(velL);
	printf(velH);
	printf((~(ID + messageLength + INST_REG_WRITE + P_GOAL_POSITION_L + posL + posH + velL + velH))&0xFF);
	if(ID != 0xfe && ReturnLevel==2)
		return ReadBuf(6);
	return 6;
}

void SCServo:: RegWriteAction()
{
	int messageLength = 2;
	byte ID =  0xFE; 
	printf(startByte);
	printf(startByte);
	printf(ID);
	printf(messageLength);
	printf(INST_ACTION);
	printf((~(ID + messageLength + INST_ACTION))&0xFF);
}

u8 SCServo:: ReadBuf(u8 len, u8 *buf)
{
	u16 n = 0;
	u8 size = 0;
	u8 ComData;
	while(n<TIMEOUT)
	{
		if(Serial.available())
		{
			if(buf)
				buf[size] = Serial.read();
			else
				ComData = Serial.read();
			size++;
			if(size>=len)
				break;
			n = 0;
		}
		n++;
	}
	return size;
}

s16 SCServo:: ReadPos(u8 ID)
{	
	u8 buf[8];
	u8 size;
	u16 pos;
	memset(buf,0,sizeof(buf));
	printf(startByte);
	printf(startByte);
	printf(ID);
	printf(4);
	printf(INST_READ);
	printf(P_PRESENT_POSITION_L);
	printf(2);
	printf((~(ID + 4 + INST_READ + P_PRESENT_POSITION_L + 2))&0xFF);
	size = ReadBuf(8, buf);
	if(size<8)
		return -1;
	pos = buf[5];
	pos <<= 8;
	pos |= buf[6];
	return (s16)pos;
}

void SCServo:: SyncWritePos(u8 ID[], u8 IDN, int position, int velocity)
{
	int messageLength = 5*IDN+4;
	u8 Sum = 0;
	byte posL =  position>>8;
	byte posH =  position&0xff;		
	
	byte velL =  velocity>>8;
	byte velH =  velocity&0xff;

	printf(startByte);
	printf(startByte);
	printf(0xfe);
	printf(messageLength);
	printf(INST_SYNC_WRITE);
	printf(P_GOAL_POSITION_L);
	printf(4);
	
	Sum = 0xfe + messageLength + INST_SYNC_WRITE + P_GOAL_POSITION_L + 4;
	int i;
	for(i=0; i<IDN; i++)
	{
		printf(ID[i]);
		printf(posL);
		printf(posH);
		printf(velL);
		printf(velH);
		Sum += ID[i] + posL + posH + velL + velH;
	}
	printf((~Sum)&0xFF);
}

I will own you for a whole life if you can help me...thank you very much!

OK. Now you need to provide links to the "SCS 15 Feetech servo motor" and "TT Linker", and a diagram showing how the servo is connected to the Arduino and how it is powered.

The servo is connected to ttlinker as shown in the picture. Power supply is from an alternator 220V AC to 7,5V DC, and ground are all the same.

I don't see anything in that picture that shows that anything is actually connected to anything.

I don't see anything in that picture that tells me what a "SCS 15 Feetech servo motor" is or what a "TT Linker" is.

Feel free to not post any links. I'll feel free to stop responding.

Hi

Did you ever get these servos to work? I have 2 and I cannot get them to move.

Cheers
Stew

I finally got these going. The version of the Arduino library that I had was incorrect. I had the same version as the person above.

Cheers
Stew

hej stewartmenday,

could please send me a link for the correct version of the library?

Thank you...
sagerchr