Controller question

Yeah, I had the same problem. I think it’s a file that comes with Microsoft Visual Basic, but you can just download a copy and unzip it to “C:\Windows\system32”.

Note: I know it’s a little sketchy to download system files from third party sites. I haven’t found a way to download this directly from Microsoft, but this is the exact copy that I have been using on my computer for about a year now with no problems I can tell.

Also, the micro serial servo controller uses a microcontroller, in this case a PIC from Microchip, to generate servo signals from serial inputs (in the same way as a cell phone uses a microcontroller to generate the key tones in response to the buttons you press). It comes pre-programmed to do this from Pololu, and you don’t have direct access to the microcontroller to change its programming. Control of many servomotors is an intense task best done with a dedicated, “low level” microcontroller. You can send it position commands from your own “high level” microcontroller, which will be free the rest of the time to do other things like read the sensors and make decisions based on that data.

-Adam

Your kinda confusing me now, couse you have already told me all i need is the micro serial servo controller, servos, a power source, a USB kabel and a USB to serial adapter to program 4-6 servos for a walking robot, and the robot will always be connected to the robot.

So if i dont want the robot to be connected to the pc (allways) what will i then have to buy.
Today i ordered the micro serial servo controller and a USB to serial adapter. Do i need anything more?

What you just ordered will let you control up to eight servos from your computer over a USB connection. They will have to be connected to your computer all the time to move.

To build your own teatherless robot (not connected to a PC) you will need to get a microcontroller (one you can program), and the equipment to program it, in addition to what you have already.

The breakdown:
[ul]-A servomotor will turn to a position and stay there only if it continually receives a position signal. Without receiving a continuous position signal a servo won’t do anything.

-The serial servo controller will take serial position commands from another device, and generate continuous position signals for several (in this case eight) servos. The servo controller you ordered uses a microcontroller to generate these signals, but you cannot reprogram it. Generating many servo position signals at once is difficult and takes a lot of precision timing, so it is good to have a dedicated device to handle it. Without serial position commands from another device, the serial servo controller won’t do anything.

-A computer or microcontroller (which is, after all, a small computer on a single chip) must generate serial commands to tell the serial servo controller what servo position commands to generate.

-To use a USB port, rather than a serial port, to command the serial servo controller from your PC, you will need a USB to Serial adapter.[/ul]
So, what you have to start with is:
[Servos]—[Serial Servo Controller]—[USB/Serial Adapter]—[PC]

To make your robot work without a constant connection to your PC, you will need:
[Servos]—[Serial Servo Controller]—[Microcontroller]-/ /-[Microcontroller Programmer]–[PC]
(Note: Once you have programmed the microcontroller, you can disconnect the programmer and the rest of your robot will work on its own).

To make your robot walker work without a constant connection to your PC, you will need to get a microcontroller, a programmer for that microcontroller, and learn how to write programs for that microcontroller. Any microcontroller with “asynchronous” serial hardware will do, and you can even fake a serial signal using software in a microcontroller that doesn’t. The point is, you have a whole lot of choices.

Learning to program and use a microcontroller is quite an undertaking, and AVR microcontrollers (like the ones made by Pololu) are not really suited for beginners, which is why I recommend some sort of microcontroller starter book/kit. Once you have experience using it, you can take the microcontroller from your kit and put it in your robot. In the meantime, you can start building your robot, while controlling it from your computer.

I hope that clears everything up!

-Adam

Yeah i think so thank you, but i decided to not order the kit anyway.
So i can program it (with codes)? Or can i just move each individual servo using, eks. the scroll bars on the program you offered me to try servo with!?
Sry for posting so many questions that you probal allready have answared, but English is not my motherlanguage and this is my first time i have tryed microcontrollers, so i dont want to order something that doesn’t work. I was so certein that i only had to order a serial servo controller and a USB to serial adapter to get my robot working. Couse im using it in a contest (money involved) so i need something that work pretty individual so no hands get shown in the film

The program I showed you (with the scroll bars) is an easy way to test your robot by making the servos move, and to get ideas about how to make it walk.

You can write a program that will send serial commands to make the robot move however you want, and that program will run either on your PC (connected to your robot by the USB cable) or on a microcontroller (built into your robot). You don’t have to push any keys!

-Adam

Ok now everything seems more clearly!
A final question (i think :P) Im going to a class this summer break, where me and the other in the class will learn how to program robots (i think we will use lego mindstormers or something) And i just got a mail where they said we have to bring or own laptop, on this laptop we will install a program making it possible to program these robots, so my question was; Can i use this program im going to use in the class on my homemade robot? Or does it all depend on the serial servo controller? I dont know what program we’ll be using so it may be hard for you to tell so maybe i will just check it out.
Edit: I diden’t see this before just now (something wrong with my winzip)
The winzip file you gave me with what should be a program to test my servos is just a scratch pad with a lot more then i will post, thats the only file in the winzip files
Here’s some of the text in the scratch pad:

MZ

Lego mindstorms are a great introduction to what you can do with a microcontroller (the NXT lego “brick” is based on an ARM microcontroller) but not so much how to do it. The latest mindstorms software is based on LabView (drag and drop instruction blocks), so it should be quite similar to the “foreward()-left()” type robot simulator you were looking at before.

Unfortunately it will not help you control the Pololu serial servo controller. To do this you will need to write a computer program that sends data out a serial port. How you do this depends on what language you want to write the program in. Out of curiosity, have you used a programming language before?

Finally, the file you unzipped is the correct file. If you copy the unzipped file to your “C:\Windows\system32” directory, the servo slider test program should run properly.

-Adam

No i have never used a programming language before but i have heard a lot about the c++. This is going to be a BIG topic, because im going to need a lot of help when i get the parts, it sound really difficault to write a computer program that send data out a serial port…! :?

So even if i haven’t got the products yet i want to know a thing. At the other robot forum im on theres a topic where people helpt a guy witht microcontroller and programmer. They gave examples to begin with eks: the Parallax microcontroller where you get a free BASIC programmer you can download from there web page and use it to program the microcontroller. There is no program for the Pololu microcontroller i ordered, so i dont know where to write my codes!!! :open_mouth:

You can make a program that will run on your computer and make your robot move. There are lots of ways to do it in lots of different languages, and free code compilers for most of them. Pololu has an example of how to do this in the C language here.

You might want to work through the example to get a feel for it. I’m not terribly fond of this example, since it uses a Unix-like emulator. If you’re interested in learning a little C programming for Windows I could point you to a free compiler and send you an old servo control program I wrote as a starting point.

If you haven’t already, you should also read through the servo controller user’s guide to get an idea of how the commands work.

-Adam

Man ure just so helpfull, thank u so much, you dont have to send me ure old servo control program yet, i think im going to read through everything on the links you gave me until i understand everything…Thanks again! :stuck_out_tongue:

Edit: Can i use this visual program for the microcontroller?: niplesoft.net/english/index.htm

It looks like the program you linked is designed to program PICs, but you aren’t programming a microcontroller, you’re writing a program for your computer that will talk to your servo controller through a serial port. If you want a visual programming environment, you could use Visual Basic/C#/C++. The Express 2005 editions are free.

msdn.microsoft.com/vstudio/express/downloads/

- Ben

I downloaded the program but i dont find a place to write or make visiual things… :cry:
By the way i chose the C#.
So i think im going to write the program myself or something, even though i have no idea how to do it!

Edit: can u send me your old servo program anyway?

Yeah, the “Visual” in MS Visual Basic/C/C++ refers to the fact that you can make Windows-style graphical interfaces more easily. The code is still bare text. I’m looking for that servo-control program now.

-Adam

Okay, I tried to clean this up and comment it a little bit. It’s never good to do this, but I haven’t actually tested this on a servo controller in its current state (my servo controller is at work, of course!).

I’ll paste the complete source code below, or you can download a tab-formatted version of the source code here.

The only parts you’ll want to mess with to start are inside the “main” function. You’ll need to change the line:
comPort=openPort(1);//PUT YOUR COM PORT NUMBER HERE!
to use the number of your com port, and you’re ready to try it out. It has a simple keyboard interface to start, and it will print out what keys do what.

It has a few functions like put(servo, angle), which sets servo number servo to angle angle, and neutral() which does what it sounds like (comments are pretty explicit too). All of these functions use the Pololu absolute position command, but you might want to try using other things like the servo speed control commands later.

There is also a millisecond delay function waitMS(), which you may find useful in generating your walking code (for example, waitMS(1000) will cause a 1 second delay before the next command).

If you have trouble getting this to compile in MS Visual C, you might try the free C and C++ compiler I use, DevC++

Welcome to console programming in C!

-Adam

[code]/*
Pololu Serial Servo Controller Test Program
Adam Borrell
7/02/07
*/

#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <conio.h>
#include <time.h>

//IMPORTANT FUNCTION PROTOTYPES
HANDLE openPort(int);//Serial protocol stuff, don’t worry about it
HANDLE comPort;//Serial protocol stuff, don’t worry about it
void put(int servo, int angle);//Moves servo (0-7) to angle (500-5500)
void servoOff();//Stops signal to all servos, analog servos will go slack, digital servos wont!
void neutral();//Sends all servos to halfway between max and min
void waitMS(int ms);//Milisecond delay function

static int min=500, max=5500, step=50;
int angles[8]={3000,3000,3000,3000,3000,3000,3000,3000};
int done=0;

int main(){
char input[32];
int i;

printf("Pololu Serial Servo Controller Test Program\n\n");

comPort=openPort(1);//***PUT YOUR COM PORT NUMBER HERE!***
if(done){
	printf("Program Terminated!\n");
	system("PAUSE");
	return;
}

waitMS(1000);//***Useless example of the wait function***
neutral();

printf("Commmands:\n");
printf("A - Increase servo 0 position\n");
printf("Z - Decrease servo 0 position\n");
printf("S - Increase servo 1 position\n");
printf("X - Decrease servo 1 position\n");
printf(".........\n");	
printf("K - Increase servo 1 position\n");
printf("< - Decrease servo 1 position\n");
printf("Spacebar - Emergency Servo Stop (WARNING: no effect on digital servos!)\n");
printf("Backspace - quit\n\n");

while (!done) {//***Simple keyboard interface
	*input = getch();
	switch(*input){
		case ' '://spacebar
			servoOff();
			printf("Emergency Servo Stop\n");
			break;
		case 8://backspace
			done = 1;
			break;
		case'a':
		case'A':
			i=0;
			if(angles[i]<=(max-step)) angles[i]+=step;
			put(i,angles[i]);
			break;
		case'z':
		case'Z':
			i=0;
			if(angles[i]>=(min+step)) angles[i]-=step;
			put(i,angles[i]);
			break;
		case's':
		case'S':
			i=1;
			if(angles[i]<=(max-step)) angles[i]+=step;
			put(i,angles[i]);
			break;
		case'x':
		case'X':
			i=1;
			if(angles[i]>=(min+step)) angles[i]-=step;
			put(i,angles[i]);
			break;
		case'd':
		case'D':
			i=2;
			if(angles[i]<=(max-step)) angles[i]+=step;
			put(i,angles[i]);
			break;
		case'c':
		case'C':
			i=2;
			if(angles[i]>=(min+step)) angles[i]-=step;
			put(i,angles[i]);
			break;
		case'f':
		case'F':
			i=3;
			if(angles[i]<=(max-step)) angles[i]+=step;
			put(i,angles[i]);
			break;
		case'v':
		case'V':
			i=3;
			if(angles[i]>=(min+step)) angles[i]-=step;
			put(i,angles[i]);
			break;
		case'g':
		case'G':
			i=4;
			if(angles[i]<=(max-step)) angles[i]+=step;
			put(i,angles[i]);
			break;
		case'b':
		case'B':
			i=4;
			if(angles[i]>=(min+step)) angles[i]-=step;
			put(i,angles[i]);
			break;
		case'h':
		case'H':
			i=5;
			if(angles[i]<=(max-step)) angles[i]+=step;
			put(i,angles[i]);
			break;
		case'n':
		case'N':
			i=5;
			if(angles[i]>=(min+step)) angles[i]-=step;
			put(i,angles[i]);
			break;
		case'j':
		case'J':
			i=6;
			if(angles[i]<=(max-step)) angles[i]+=step;
			put(i,angles[i]);
			break;
		case'm':
		case'M':
			i=6;
			if(angles[i]>=(min+step)) angles[i]-=step;
			put(i,angles[i]);
			break;
		case'k':
		case'K':
			i=7;
			if(angles[i]<=(max-step)) angles[i]+=step;
			put(i,angles[i]);
			break;
		case',':
		case'<':
			i=7;
			if(angles[i]>=(min+step)) angles[i]-=step;
			put(i,angles[i]);
			break;
		default:
			break;
	}
}
servoOff();
printf("Program Terminated!\n");
system("PAUSE");
return;

}

void neutral(){
int i;
for(i=0;i<9;i++){
put(i,(max+min)/2);
}
printf("\n");
}

void put(int servo, int angle){
unsigned char buff[6];
DWORD len;

unsigned short int temp;
unsigned char pos_hi,pos_low;

temp=angle&0x1f80;
pos_hi=temp>>7;
pos_low=angle & 0x7f;

buff[0]=0x80;//start byte
buff[1]=0x01;//device id
buff[2]=0x04;//command number
buff[3]=servo;//servo number
buff[4]=pos_hi;//data1
buff[5]=pos_low;//data2
WriteFile(comPort, &buff, 6, &len, 0);

printf("Servo %d Set to %d\n", servo, angle);

return;

}

void servoOff(){
unsigned char buff[6];
DWORD len;
int servo;

buff[0]=0x80;//start byte
buff[1]=0x01;//device id
buff[2]=0x00;//command number
buff[4]=0x0f;//data1
for(servo=0;servo<8;servo++) {
	buff[3]=servo;//servo number
	WriteFile(comPort, &buff, 5, &len, 0);
	}
return;

}

void waitMS(int ms){
clock_t endwait;
endwait=clock()+ms*CLOCKS_PER_SEC/1000;
while(clock()<endwait);
}

HANDLE openPort(int portnum){
char port[]=“com”, pnum[]=“Error”;
itoa(portnum,pnum,10);
strcat(port,pnum);

HANDLE serial=CreateFile(port,GENERIC_READ|GENERIC_WRITE,0,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);
if(serial==INVALID_HANDLE_VALUE){
	if(GetLastError()==ERROR_FILE_NOT_FOUND){
		printf("Error, %s Not Found\n", port);
		done=1;
		return;
	}
	printf("Com Error\n");
	done=1;
	return;
}

DCB dcbSerialParams={0};
dcbSerialParams.DCBlength=sizeof(dcbSerialParams);

if(!GetCommState(serial, &dcbSerialParams)){
	printf("Com State Error\n");
	done=1;
	return;
}

dcbSerialParams.BaudRate=CBR_19200;//CBR_baudrate
dcbSerialParams.ByteSize=8;
dcbSerialParams.Parity=NOPARITY;//NOPARITY, ODDPARITY, EVENPARITY
dcbSerialParams.StopBits=ONESTOPBIT;//ONESTOPBIT, ONE5STOPBITS, TWOSTOPBITS

if(!SetCommState(serial, &dcbSerialParams)){
	printf("Serial Protocol Error\n");
	done=1;
	return;
}

COMMTIMEOUTS timeouts={0};
timeouts.ReadIntervalTimeout=50;
timeouts.ReadTotalTimeoutConstant=50;
timeouts.ReadTotalTimeoutMultiplier=10;
timeouts.WriteTotalTimeoutConstant=50;
timeouts.WriteTotalTimeoutMultiplier=10;

if(!SetCommTimeouts(serial,&timeouts)){
	printf("Timeout Setting Error\n");
	done=1;
	return;
}

return serial;

}
[/code]

Thanks, i’ll try it once i recieve the products.
By the way, u know any step by step PDF files or something on how to learn how to make C codes from scratch?
I want to learn to make them soo bad, not no though i have the code u gave me i just adjust the servo angle and all of that, its just eks if i want to make codes where i include sensors and things like that…!

Some questions about that code:
When every this shows:
void put(int servo, int angle){
I will put, eks:
void put (2 servo, 5500 angle) { |RIGHT?|

This: void waitMS(int ms);
EKS: void waitMS(int ms); 1000
|RIGHT?|

  • Add the COM number, that all i have to add right?

And when i pressed the button: RUN
This came: Source file not compiled, i know where to compile but what does it mean, what will i have to do?

Just wanna make sure u’re still there?

So i just recieved the products from Pololu, not the servos though (yet)!

So this is a “drawing” of the servo controller (see if i got it right, pins only):

      ---------                    

USB? -> | … .::expressionless: <-Power 6V
|. :::expressionless:
|: :::expressionless: <-Servos (0-7)
|: :::expressionless:
----------

Compere this to the real picture of the servo controller and u see the pins are at the right places, so u can see im a little confused about where to connect the USB to serial adapter on the servo controller…Couse the USB to serial adapter got so many pins, do i only have to use 2 of them?

There is a good C beginner tutorial here. Since you’re programming in C and not C++, you only want to look at the topics listed under “C Tutorial” (and do try the quizzes!)

The only things you should change in the code I sent you are inside the main() function. For starters, find the line that says:

[ul]comPort=openPort(1);//PUT YOUR COM PORT NUMBER HERE![/ul]
If your USB-to-Serial adapter is installed as COM1, you don’t need to change anything, but if it is installed as another port, COM3 for example, you would change this line to read:
[ul]comPort=openPort(3);//PUT YOUR COM PORT NUMBER HERE!
[/ul]
Now find the line that reads:
[ul]waitMS(1000);//Useless example of the wait function
neutral();[/ul]
This pauses the program for 1 second, then sends all of the servos to their neutral positions. You can add to the program here. For example, if I wanted to wait half a second, then send servo 0 to position 3500, I would write this:
[ul]waitMS(1000);//Useless example of the wait function
neutral();
waitMS(500);
put(0,3500);[/ul]
The changes you said you made to the original program would keep the program from compiling because they do not follow the C language format. Those are usually easier mistakes to find (although not always), since the compiling program should give you a list of where the errors are. Harder mistakes to find are ones that are properly formatted, but do something other than what you intended.

Before you start editing the code, see if you can get the original to compile and run, then you will know your compiler is set up properly. After running the waitMS and neutral functions, the program should end up in a menu that lets you use the keyboard to control the servos, and tells you what servo you have moved to what position. This way you can figure out what moves you want to make, and add them to your program!

As for wiring, there are only a few connections to make. For reference:


NOTE: This picture shows the servo controller with the “protocol selection jumper” on. You should not have this jumper on while using the code I sent you.

Obviously you need to connect your USB-to-Serial adapter to your computer with a USB cable. You will only need to make two connections between the USB-to-Serial adapter and the servo-controller:
[ul]USB-to-Serial adapter GND to servo controller GND (either pin)
USB-to-Serial adapter TX to servo controller “logic-level serial input”[/ul]
You will also need a power source (4V-6V) for the servos, connected to the “servo power” + and - pins. If this power source is greater than 5V, you can also run the servo controller electronics from it by connecting the two pins labeled “Vcc=Vs Jumper”. If your servo power source is not greater than 5V, you will need to connect a separate power source to the servo controller VIN and GND pins.

It should be possible to power the servo controller electronics (but not the servos themselves) from the USB-to-serial adapter by connecting the “Vbus (+5V)” pin on the adapter to the “VIN (5-16V)” pin on the servo controller, but this is not guaranteed to work (your USB bus voltage may be below 5V).

OBVIOUSLY you should only have one of these three power sources connected at once (Vcc=Vs, Vbus connected to VIN, or a separate power supply connected to VIN).

You’ll have your servos twitching in no time!

-Adam

I just tested that code with my serial servo controller and (to my amazement) it seems to work fine. I only tried one servo, so there may be typos with others still. Let me know if you find any!

-Adam

To start with, sry for the drawing i dident know it was turning into smilys…

Ok so now i will try the code u sent me without any adding to it, and the USB to serial adapter should be connected like this:

USB-to-Serial adapter GND to servo controller GND (either pin)

USB-to-Serial adapter TX to servo controller “logic-level serial input”

But the prorgram u said i could download: devcpp.exe (devC++)
Could i run your code in that program even if its only C not C+?

A question about the USB to serial adapter: I think the USB to serial adapter has 14 holes through it or something and 14 pins in the package all on a straight line, should i brake them up in 3 lines with 4-5 pins in each and put them in the holes?

And also, there will be pins un-used on the servo controller right? So i dont have to worry about some pins.

I think i will begin soon, just got to recieve the servos!

Edit: And i will have to remove the blue thing attached to the servo controller? But thats soldered on how will i do that?