Song time xD
September 30th, 2010Commited VisualCortex code!
September 30th, 2010I just commited the VisualCortex code for guarddog on github , the whole project is now availiable as opensource licensed GPL v3
Next thing on list is connect pathfinding with ultrasonic values!
SRF-05 sensors mounted on guarddog
September 30th, 2010GuardDog arduino connection done!
September 30th, 2010I just finished merging the new arduino code with the existing motor library..!
The reason that I didnt make a seperate library is that arduino will also have 2 servo motors that will control the head movement so it all belongs to motor lib functionality
This is a very good tutorial on Linux serial interfacing with a device i.e. arduino
Functions RobotGetUltrasonic(unsigned int dev); , RobotGetAccelerometerX(unsigned int dev); , RobotGetAccelerometerY(unsigned int dev); will now be exposed to the robokernel
See more on the GuardDog git repository
For now the arduino the connection diagram is the following
and the code is the following
Code:
const int numOfReadings = 10; // number of readings to take/ items in the array | |
// setup pins and variables for SRF05 sonar device | |
int sampleultrasonic=1; | |
int sampleaccelerometer=1; | |
unsigned int tickcount=0; | |
| |
struct ultrasonic | |
{ | |
int echoPin; // SRF05 echo pin (digital 2) | |
int initPin; | |
unsigned int proximity; | |
int arrayIndex; // arrayIndex of the current item in the array | |
int total; // stores the cumlative total | |
int averageDistance; // stores the average value | |
int readings[numOfReadings]; // stores the distance readings in an array | |
}; | |
| |
struct memsic2125 | |
{ | |
int xPin,yPin; | |
int pulseX,pulseY; | |
int accelerationX,accelerationY; | |
}; | |
| |
struct ultrasonic sensor1,sensor2; | |
struct memsic2125 accelerometer; | |
| |
unsigned long pulseTime = 0; // stores the pulse in Micro Seconds | |
unsigned long distance = 0; // variable for storing the distance (cm) | |
unsigned int proximity=0; | |
| |
void setupAccelerometer(struct memsic2125 * accel,int xpin,int ypin) | |
{ | |
pinMode(xpin, INPUT); | |
pinMode(ypin, INPUT); | |
accel->xPin=xpin; | |
accel->yPin=ypin; | |
accel->pulseX=0; | |
accel->pulseY=0; | |
accel->accelerationX=0; | |
accel->accelerationY=0; | |
} | |
| |
| |
void setupUltrasonic(struct ultrasonic *ultr,int echopin,int initpin) | |
{ | |
pinMode(initpin, OUTPUT); // set init pin 3 as output | |
pinMode(echopin, INPUT); // set echo pin 2 as input | |
ultr->echoPin=echopin; | |
ultr->initPin=initpin; | |
for (int thisReading = 0; thisReading < numOfReadings; thisReading++) { ultr->readings[thisReading] = 0; } | |
ultr->proximity=0; | |
ultr->arrayIndex=0; // arrayIndex of the current item in the array | |
ultr->total=0; // stores the cumlative total | |
ultr->averageDistance=0; | |
} | |
| |
//setup | |
void setup() | |
{ | |
setupUltrasonic(&sensor1,2,3); | |
setupUltrasonic(&sensor2,4,5); | |
setupAccelerometer(&accelerometer,7,6); | |
| |
// initialize the serial port, lets you view the | |
// distances being pinged if connected to computer | |
Serial.begin(38400); | |
} | |
// execute | |
| |
| |
int sampleUltrasonic(struct ultrasonic *ultr) | |
{ | |
digitalWrite(ultr->initPin, HIGH); // send 10 microsecond pulse | |
delayMicroseconds(10); // wait 10 microseconds before turning off | |
digitalWrite(ultr->initPin, LOW); // stop sending the pulse | |
pulseTime = pulseIn(ultr->echoPin, HIGH); // Look for a return pulse, it should be high as the pulse goes low-high-low | |
distance = pulseTime/58; // Distance = pulse time / 58 to convert to cm. | |
ultr->total= ultr->total - ultr->readings[ultr->arrayIndex]; // subtract the last distance | |
ultr->readings[ultr->arrayIndex] = distance; // add distance reading to array | |
ultr->total= ultr->total + ultr->readings[ultr->arrayIndex]; // add the reading to the total | |
| |
ultr->arrayIndex = ultr->arrayIndex + 1; // go to the next item in the array | |
| |
int proximity=0; | |
| |
if (ultr->arrayIndex >= numOfReadings) { ultr->arrayIndex = 0; } | |
ultr->averageDistance = ultr->total / numOfReadings; // calculate the average distance | |
// if the distance is less than 255cm then change the brightness of the LED | |
//if (ultr->averageDistance < 255) { proximity = 255 - ultr->averageDistance; } // this means the smaller the distance the brighterthe LED. | |
proximity=ultr->averageDistance; | |
| |
return proximity; | |
} | |
| |
| |
void sampleAccelerometer(struct memsic2125 * accel) | |
{ | |
accel->pulseX = pulseIn(accel->xPin,HIGH); | |
accel->pulseY = pulseIn(accel->yPin,HIGH); | |
accel->accelerationX = ((accel->pulseX / 10) - 500) * 8; | |
accel->accelerationY = ((accel->pulseY / 10) - 500) * 8; | |
} | |
| |
| |
| |
void loop() | |
{ | |
++tickcount; | |
| |
if ( sampleultrasonic ) | |
{ | |
//analogWrite(redLEDPin, redLEDValue); // Write current value to LED pins | |
//Serial.println(averageDistance, DEC); // print out the average distance to the debugger | |
int proximity1 = sampleUltrasonic(&sensor1); | |
Serial.print("proximity(1,"); | |
Serial.print(proximity1); | |
Serial.println(")"); | |
| |
int proximity2 = sampleUltrasonic(&sensor2); | |
Serial.print("proximity(2,"); | |
Serial.print(proximity2); | |
Serial.println(")"); | |
} | |
| |
if ( sampleaccelerometer ) | |
{ | |
sampleAccelerometer(&accelerometer); | |
Serial.print("accelerometers("); | |
Serial.print(accelerometer.accelerationX); | |
// print a tab character: | |
Serial.print(","); | |
Serial.print(accelerometer.accelerationY); | |
Serial.println(")"); | |
} | |
| |
Serial.print("tickcount("); | |
Serial.print(tickcount); | |
Serial.println(")"); | |
| |
Serial.println("#"); /*MARK THE END OF TRANSMISSION*/ | |
| |
delay(100); // wait 100 milli seconds before looping again | |
} |
Added Accelerometer code
September 28th, 2010Added accelerometer code
Code:
const int numOfReadings = 10; // number of readings to take/ items in the array | |
// setup pins and variables for SRF05 sonar device | |
| |
struct ultrasonic | |
{ | |
int echoPin; // SRF05 echo pin (digital 2) | |
int initPin; | |
unsigned int proximity; | |
int arrayIndex; // arrayIndex of the current item in the array | |
int total; // stores the cumlative total | |
int averageDistance; // stores the average value | |
int readings[numOfReadings]; // stores the distance readings in an array | |
}; | |
| |
struct memsic2125 | |
{ | |
int xPin,yPin; | |
int pulseX,pulseY; | |
int accelerationX,accelerationY; | |
}; | |
| |
struct ultrasonic sensor1,sensor2; | |
struct memsic2125 accelerometer; | |
| |
unsigned long pulseTime = 0; // stores the pulse in Micro Seconds | |
unsigned long distance = 0; // variable for storing the distance (cm) | |
unsigned int proximity=0; | |
| |
void setupAccelerometer(struct memsic2125 * accel,int xpin,int ypin) | |
{ | |
pinMode(xpin, INPUT); | |
pinMode(ypin, INPUT); | |
accel->xPin=xpin; | |
accel->yPin=ypin; | |
} | |
| |
| |
void setupUltrasonic(struct ultrasonic *ultr,int echopin,int initpin) | |
{ | |
pinMode(initpin, OUTPUT); // set init pin 3 as output | |
pinMode(echopin, INPUT); // set echo pin 2 as input | |
ultr->echoPin=echopin; | |
ultr->initPin=initpin; | |
for (int thisReading = 0; thisReading < numOfReadings; thisReading++) { ultr->readings[thisReading] = 0; } | |
ultr->proximity=0; | |
ultr->arrayIndex=0; // arrayIndex of the current item in the array | |
ultr->total=0; // stores the cumlative total | |
ultr->averageDistance=0; | |
} | |
| |
//setup | |
void setup() | |
{ | |
setupUltrasonic(&sensor1,2,3); | |
setupUltrasonic(&sensor2,4,5); | |
setupAccelerometer(&accelerometer,7,6); | |
| |
// initialize the serial port, lets you view the | |
// distances being pinged if connected to computer | |
Serial.begin(9600); | |
} | |
// execute | |
| |
| |
int sampleUltrasonic(struct ultrasonic *ultr) | |
{ | |
digitalWrite(ultr->initPin, HIGH); // send 10 microsecond pulse | |
delayMicroseconds(10); // wait 10 microseconds before turning off | |
digitalWrite(ultr->initPin, LOW); // stop sending the pulse | |
pulseTime = pulseIn(ultr->echoPin, HIGH); // Look for a return pulse, it should be high as the pulse goes low-high-low | |
distance = pulseTime/58; // Distance = pulse time / 58 to convert to cm. | |
ultr->total= ultr->total - ultr->readings[ultr->arrayIndex]; // subtract the last distance | |
ultr->readings[ultr->arrayIndex] = distance; // add distance reading to array | |
ultr->total= ultr->total + ultr->readings[ultr->arrayIndex]; // add the reading to the total | |
| |
ultr->arrayIndex = ultr->arrayIndex + 1; // go to the next item in the array | |
| |
int proximity=0; | |
| |
if (ultr->arrayIndex >= numOfReadings) { ultr->arrayIndex = 0; } | |
ultr->averageDistance = ultr->total / numOfReadings; // calculate the average distance | |
// if the distance is less than 255cm then change the brightness of the LED | |
if (ultr->averageDistance < 255) { proximity = 255 - ultr->averageDistance; } // this means the smaller the distance the brighterthe LED. | |
| |
| |
return proximity; | |
} | |
| |
| |
void sampleAccelerometer(struct memsic2125 * accel) | |
{ | |
accel->pulseX = pulseIn(accel->xPin,HIGH); | |
accel->pulseY = pulseIn(accel->yPin,HIGH); | |
accel->accelerationX = ((accel->pulseX / 10) - 500) * 8; | |
accel->accelerationY = ((accel->pulseY / 10) - 500) * 8; | |
} | |
| |
void loop() | |
{ | |
| |
| |
| |
//analogWrite(redLEDPin, redLEDValue); // Write current value to LED pins | |
//Serial.println(averageDistance, DEC); // print out the average distance to the debugger | |
int proximity = sampleUltrasonic(&sensor1); | |
Serial.print("Proximity 1 : "); | |
Serial.println(proximity); | |
| |
proximity = sampleUltrasonic(&sensor2); | |
Serial.print("Proximity 2 : "); | |
Serial.println(proximity); | |
| |
| |
sampleAccelerometer(&accelerometer); | |
Serial.print("Accelerometers : "); | |
Serial.print(accelerometer.accelerationX); | |
// print a tab character: | |
Serial.print("\t"); | |
Serial.print(accelerometer.accelerationY); | |
Serial.println(); | |
| |
delay(100); // wait 100 milli seconds before looping again | |
} |
Integrated 2nd Ultrasonic sensor
September 27th, 2010I finished soldering cables together and sorting them out so now i can finally sample both ultrasonic sensors at the same time and transmit their status over serial usb!
I also improved the code found on the site I mentioned some days before , by grouping together everything so I will be able to add functionallity without spaghetti code ( on a chip ) ..
I am also thinking of the protocol that I will create to perform functions on the arduino
I like this kind of things very much :o) ..!
When it will be ready I will also upload in in the robot github repo
On other news tommorow is my last class exam but I am not sure I will pass it if only my work here could be taken into account..
Code:
const int numOfReadings = 10; // number of readings to take/ items in the array | |
// setup pins and variables for SRF05 sonar device | |
| |
struct ultrasonic | |
{ | |
int echoPin; // SRF05 echo pin (digital 2) | |
int initPin; | |
unsigned int proximity; | |
int arrayIndex; // arrayIndex of the current item in the array | |
int total; // stores the cumlative total | |
int averageDistance; // stores the average value | |
int readings[numOfReadings]; // stores the distance readings in an array | |
}; | |
| |
| |
struct ultrasonic sensor1,sensor2; | |
| |
unsigned long pulseTime = 0; // stores the pulse in Micro Seconds | |
unsigned long distance = 0; // variable for storing the distance (cm) | |
unsigned int proximity=0; | |
| |
| |
| |
void setupUltrasonic(struct ultrasonic *ultr,int echopin,int initpin) | |
{ | |
pinMode(initpin, OUTPUT); // set init pin 3 as output | |
pinMode(echopin, INPUT); // set echo pin 2 as input | |
ultr->echoPin=echopin; | |
ultr->initPin=initpin; | |
for (int thisReading = 0; thisReading < numOfReadings; thisReading++) { ultr->readings[thisReading] = 0; } | |
ultr->proximity=0; | |
ultr->arrayIndex=0; // arrayIndex of the current item in the array | |
ultr->total=0; // stores the cumlative total | |
ultr->averageDistance=0; | |
} | |
| |
//setup | |
void setup() | |
{ | |
setupUltrasonic(&sensor1,2,3); | |
setupUltrasonic(&sensor2,4,5); | |
| |
// initialize the serial port, lets you view the | |
// distances being pinged if connected to computer | |
Serial.begin(9600); | |
} | |
// execute | |
| |
| |
int sampleUltrasonic(struct ultrasonic *ultr) | |
{ | |
digitalWrite(ultr->initPin, HIGH); // send 10 microsecond pulse | |
delayMicroseconds(10); // wait 10 microseconds before turning off | |
digitalWrite(ultr->initPin, LOW); // stop sending the pulse | |
pulseTime = pulseIn(ultr->echoPin, HIGH); // Look for a return pulse, it should be high as the pulse goes low-high-low | |
distance = pulseTime/58; // Distance = pulse time / 58 to convert to cm. | |
ultr->total= ultr->total - ultr->readings[ultr->arrayIndex]; // subtract the last distance | |
ultr->readings[ultr->arrayIndex] = distance; // add distance reading to array | |
ultr->total= ultr->total + ultr->readings[ultr->arrayIndex]; // add the reading to the total | |
| |
ultr->arrayIndex = ultr->arrayIndex + 1; // go to the next item in the array | |
| |
int proximity=0; | |
| |
if (ultr->arrayIndex >= numOfReadings) { ultr->arrayIndex = 0; } | |
ultr->averageDistance = ultr->total / numOfReadings; // calculate the average distance | |
// if the distance is less than 255cm then change the brightness of the LED | |
if (ultr->averageDistance < 255) { proximity = 255 - ultr->averageDistance; } // this means the smaller the distance the brighterthe LED. | |
| |
| |
return proximity; | |
} | |
| |
void loop() | |
{ | |
| |
| |
| |
//analogWrite(redLEDPin, redLEDValue); // Write current value to LED pins | |
//Serial.println(averageDistance, DEC); // print out the average distance to the debugger | |
int proximity = sampleUltrasonic(&sensor1); | |
Serial.println("Proximity 1 "); | |
Serial.println(proximity); | |
| |
proximity = sampleUltrasonic(&sensor2); | |
Serial.println("Proximity 2 "); | |
Serial.println(proximity); | |
| |
| |
delay(100); // wait 100 milli seconds before looping again | |
} |
Test b2evolution -> twitter -> fb
September 26th, 2010Retesting b2evolution -> twitter -> facebook syndication..