by MarcoP » Fri Jun 29, 2012 3:59 pm
by MarcoP
Fri Jun 29, 2012 3:59 pm
Hi
The main limitation we have had regarding the Wild Thumper was the ability to do speed control, due to the lack of encoders.
So we have taken care of that:
We got encoders for the wheels.
This encoder consists of a stainless steel disk with 60 slots, that rotates between an infra-red emitter and receiver. This gives us a digital signal that changes 60 times per wheel rotation.
The disk goes onto the shaft and the wheel goes on top.
We designed a small 3d printed part that secures the encoder pcb.
The only modification needed is to replace the normal shaft screw with set screws so that they do not collide with the encoder pcb.
We only added the encoder on one wheel on each side, since most of the time all wheels are in contact with the ground, meaning the wheels from either side will rotate in sync.
The objective now is to do accurate speed control.
But given we have now precise feedback on wheel speed we wanted to know something: How does the actual speed of the motors vary with pwm?
We created then a small program for the arduino that cycles trough all possible throttles (0 to 255) and measures speed and acceleration.
- Code: Select all
#define LmotorA 3 // Left motor H bridge, input A
#define LmotorB 11 // Left motor H bridge, input B
#define RmotorA 5 // Right motor H bridge, input A
#define RmotorB 6 // Right motor H bridge, input B
int lencoderPin = 2;
int rencoderPin = 4;
int throttle;
int rticks = 0,lticks = 0;
int rSpeed = 0,lSpeed = 0;
int rAccel = 0,lAccel = 0;
boolean rstate,lstate;
unsigned int temp;
void setup()
{
pinMode(lencoderPin, INPUT);
pinMode(rencoderPin, INPUT);
Serial.begin(115200); // open the serial port at 9600 bps:
}
void loop()
{
Serial.println("Throttle;rAccel;lAccel;rSpeed;lSpeed ");
lstate!=digitalRead(lencoderPin);
rstate!=digitalRead(rencoderPin);
for (throttle=0;throttle<256;throttle++){
analogWrite(LmotorA, 0);
analogWrite(LmotorB, throttle);
analogWrite(RmotorA, 0);
analogWrite(RmotorB, throttle);
delay(50); //give 50ms second to gain some speed
unsigned long StartTime = millis();
rticks=0;
lticks=0;
do{
if(lstate!=digitalRead(lencoderPin)){
lticks++;
lstate=!lstate;
}
if(rstate!=digitalRead(rencoderPin)){
rticks++;
rstate=!rstate;
}
}while((millis()-StartTime)<100); //measure ticks during 100 ms
rAccel=rticks*10;
lAccel=lticks*10;
delay(1000); //give it 1 second to stabilize speed
rticks=0;
lticks=0;
StartTime = millis();
do{
if(lstate!=digitalRead(lencoderPin)){
lticks++;
lstate=!lstate;
}
if(rstate!=digitalRead(rencoderPin)){
rticks++;
rstate=!rstate;
}
}while((millis()-StartTime)<100); //measure ticks during 100 ms
rSpeed=rticks*10;
lSpeed=lticks*10;
Serial.print(throttle);
Serial.print(";");
Serial.print(rAccel);
Serial.print(";");
Serial.print(lAccel);
Serial.print(";");
Serial.print(rSpeed);
Serial.print(";");
Serial.println(lSpeed);
analogWrite(LmotorA, 0); //stop the motor(no active breaking)
analogWrite(LmotorB, 0);
analogWrite(RmotorA, 0);
analogWrite(RmotorB, 0);
delay(1000); //give it time to stop
}
throttle=0;
analogWrite(LmotorA, 0);
analogWrite(LmotorB, throttle);
analogWrite(RmotorA, 0);
analogWrite(RmotorB, throttle);
while(1);
}
If you start serial monitor the program will output values for speed and acceleration for each throttle value.
The values will be output in this format:
Throttle;rAccel;lAccel;rSpeed;lSpeed
0;10;10;0;0
1;0;0;0;0
2;0;0;0;0
3;0;0;0;0
4;0;0;0;0
5;0;0;0;0
6;0;0;0;0
7;0;0;0;0
8;0;0;0;0
9;0;0;0;0
10;0;0;0;0
11;0;0;0;0
12;0;0;0;0
13;0;0;0;0
To those who do not recognize it, this in the CSV (Comma Separated Values) file format. Meaning when the program ends, just select all of the text, paste it in Notepad and save as filename.csv.
You can now open it in Excel, where it will be nicely organized in rows and columns.
To be continued in the next post
Hi
The main limitation we have had regarding the Wild Thumper was the ability to do speed control, due to the lack of encoders.
So we have taken care of that:
We got encoders for the wheels.
This encoder consists of a stainless steel disk with 60 slots, that rotates between an infra-red emitter and receiver. This gives us a digital signal that changes 60 times per wheel rotation.
The disk goes onto the shaft and the wheel goes on top.
We designed a small 3d printed part that secures the encoder pcb.
The only modification needed is to replace the normal shaft screw with set screws so that they do not collide with the encoder pcb.
We only added the encoder on one wheel on each side, since most of the time all wheels are in contact with the ground, meaning the wheels from either side will rotate in sync.
The objective now is to do accurate speed control.
But given we have now precise feedback on wheel speed we wanted to know something: How does the actual speed of the motors vary with pwm?
We created then a small program for the arduino that cycles trough all possible throttles (0 to 255) and measures speed and acceleration.
- Code: Select all
#define LmotorA 3 // Left motor H bridge, input A
#define LmotorB 11 // Left motor H bridge, input B
#define RmotorA 5 // Right motor H bridge, input A
#define RmotorB 6 // Right motor H bridge, input B
int lencoderPin = 2;
int rencoderPin = 4;
int throttle;
int rticks = 0,lticks = 0;
int rSpeed = 0,lSpeed = 0;
int rAccel = 0,lAccel = 0;
boolean rstate,lstate;
unsigned int temp;
void setup()
{
pinMode(lencoderPin, INPUT);
pinMode(rencoderPin, INPUT);
Serial.begin(115200); // open the serial port at 9600 bps:
}
void loop()
{
Serial.println("Throttle;rAccel;lAccel;rSpeed;lSpeed ");
lstate!=digitalRead(lencoderPin);
rstate!=digitalRead(rencoderPin);
for (throttle=0;throttle<256;throttle++){
analogWrite(LmotorA, 0);
analogWrite(LmotorB, throttle);
analogWrite(RmotorA, 0);
analogWrite(RmotorB, throttle);
delay(50); //give 50ms second to gain some speed
unsigned long StartTime = millis();
rticks=0;
lticks=0;
do{
if(lstate!=digitalRead(lencoderPin)){
lticks++;
lstate=!lstate;
}
if(rstate!=digitalRead(rencoderPin)){
rticks++;
rstate=!rstate;
}
}while((millis()-StartTime)<100); //measure ticks during 100 ms
rAccel=rticks*10;
lAccel=lticks*10;
delay(1000); //give it 1 second to stabilize speed
rticks=0;
lticks=0;
StartTime = millis();
do{
if(lstate!=digitalRead(lencoderPin)){
lticks++;
lstate=!lstate;
}
if(rstate!=digitalRead(rencoderPin)){
rticks++;
rstate=!rstate;
}
}while((millis()-StartTime)<100); //measure ticks during 100 ms
rSpeed=rticks*10;
lSpeed=lticks*10;
Serial.print(throttle);
Serial.print(";");
Serial.print(rAccel);
Serial.print(";");
Serial.print(lAccel);
Serial.print(";");
Serial.print(rSpeed);
Serial.print(";");
Serial.println(lSpeed);
analogWrite(LmotorA, 0); //stop the motor(no active breaking)
analogWrite(LmotorB, 0);
analogWrite(RmotorA, 0);
analogWrite(RmotorB, 0);
delay(1000); //give it time to stop
}
throttle=0;
analogWrite(LmotorA, 0);
analogWrite(LmotorB, throttle);
analogWrite(RmotorA, 0);
analogWrite(RmotorB, throttle);
while(1);
}
If you start serial monitor the program will output values for speed and acceleration for each throttle value.
The values will be output in this format:
Throttle;rAccel;lAccel;rSpeed;lSpeed
0;10;10;0;0
1;0;0;0;0
2;0;0;0;0
3;0;0;0;0
4;0;0;0;0
5;0;0;0;0
6;0;0;0;0
7;0;0;0;0
8;0;0;0;0
9;0;0;0;0
10;0;0;0;0
11;0;0;0;0
12;0;0;0;0
13;0;0;0;0
To those who do not recognize it, this in the CSV (Comma Separated Values) file format. Meaning when the program ends, just select all of the text, paste it in Notepad and save as filename.csv.
You can now open it in Excel, where it will be nicely organized in rows and columns.
To be continued in the next post
Last edited by MarcoP on Fri Jun 29, 2012 4:08 pm, edited 1 time in total.