The first step we took was detailing our incoming signals and outgoing signals for each sub-system. Because we got some extra team members from the team that didn't make it, the sub-system Movement was designed and written by my college, Mark Goeman. This left "pick and place" and the master to me.
Here the Information scheme of pick and place:
As we decided to work with 3 arduino micro controllers, the logic scheme also had to be reworked. The first step in doing this was making an Exel sheet with all the different functions, linked together in such a way i could "click" my way trough the program.
Besides the problem of what the controller should be doing, I also spend a lot of time on how the controllers would be communicating with each other. The answer came in the form of and I2C bus. This is a communication protocol where 1 master controls the data flow of the slaves connected to the same bus. Building on this protocol the idea slowely came to being to give each slave his own "library" of commands, with the master applying logic to variables coming from the slaves, and sending new commands to the slaves.
Ask for status update --> Apply Logic ---> Send new command
While a good idea to begin with, the details make or break an idea, so I started with some simple examples to see if I could get a bit from one controller to the other, in the way I wanted it to.
This is the code of the first successful test, based off the example code supplied with arduino:
Master code:
#include <Wire.h>
void setup()
{
Wire.begin();
int(Send);
int(Request);
Serial.begin(9600);
}
byte x = 0;
void loop()
{
Send();
delay(500);
Request();
delay(500);
}
void Send()
{
Wire.beginTransmission(4);
Wire.write("x is ");
Wire.write(x);
Serial.print(x);
Serial.print(" ");
Wire.endTransmission();
x++;
}
void Request()
{
Serial.println("request ");
Wire.requestFrom(4, 3);
while(Wire.available())
{
int y = Wire.read();
Serial.print(y);
if(y==1){
x=0;
}
}
}
And the Slave code:
#include <Wire.h>
int ledPin1 = 3;
int ledPin2 = 5;
int ledPin3 = 6;
int ledPin4 = 9;
int x = 0;
int y = 0;
void setup()
{
Wire.begin(4);
Wire.onReceive(recieveEvent);
Wire.onRequest(requestEvent);
Serial.begin(9600);
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, OUTPUT);
}
void loop()
{
delay(100);
}
void recieveEvent(int howMany)
{
while(1<Wire.available())
{
char c = Wire.read();
Serial.print(c);
}
x = Wire.read();
Serial.println(x);
if(x==1){
analogWrite(ledPin1, 128);
delay(500);
analogWrite(ledPin1, 0);
}
if(x==2){
analogWrite(ledPin2, 128);
delay(500);
analogWrite(ledPin2, 0);
}
if(x==3){
analogWrite(ledPin1, 128);
analogWrite(ledPin2, 128);
delay(500);
analogWrite(ledPin1, 0);
analogWrite(ledPin2, 0);
}
if(x==4){
analogWrite(ledPin3, 128);
delay(500);
analogWrite(ledPin3, 0);
}
if(x==5){
analogWrite(ledPin1, 128);
analogWrite(ledPin3, 128);
delay(500);
analogWrite(ledPin1, 0);
analogWrite(ledPin3, 0);
}
if(x==6){
analogWrite(ledPin2, 128);
analogWrite(ledPin3, 128);
delay(500);
analogWrite(ledPin2, 0);
analogWrite(ledPin3, 0);
}
if(x==7){
analogWrite(ledPin1, 128);
analogWrite(ledPin2, 128);
analogWrite(ledPin3, 128);
delay(500);
analogWrite(ledPin1, 0);
analogWrite(ledPin2, 0);
analogWrite(ledPin3, 0);
}
if(x==8){
analogWrite(ledPin4, 128);
delay(500);
analogWrite(ledPin4, 0);
}
}
void requestEvent()
{
if(x>=8){
y=1;
}else{
y=0;
}
Wire.write(y);
Serial.print("y is ");
Serial.println(y);
}
As you can see the slave has way more code to work with, this is mainly becouse i wanted to actualy see if it was working or not, so I made a simple counter to show me the value of the bits that where send back and forth, as well as a reset when the value exceeded my LED counter.
While I was exploring some of the abilities of C++ and arduino to form an autonomous "calculator", the full I/O list also came to being. Together with my college Mark Goeman, who would be handling the digital electronics and line tracking. He came up with the schematics for a beautiful system that incorporated all digital components, including the micro controllers, H - bridges, bus systems, connections with sensors and actuators, and 2 wires to connect the battery with. For this to work with minimal system errors however, we had to specify every wire, every pin and every resistor.
This scheme shows the sockets coming out of the housing, 2 per micro controller, and what wire is connected to what pin, and what kind of data should be going trough it. Each socket consists of an Ethernet cable, thus having 8 wires. This eases a lot of the "random wires" problems that tend to happen with complex electronics, and it shields somewhat against electromagnetic influences.
This I/O scheme is more for my side of the system, it consist of all the arduino pins, and their connection with the outside world. Because tracking wires back into the system is a simple no-go, this scheme is also necessary because it gives me an overview of the pins I need to link with the internal processes.
Please note: I am writing this after the final project day, so the schemes as presented here are up to date and resemble how our robot was wired after all the initial errors had been fixed!



Geen opmerkingen:
Een reactie posten