Project developement
Machine Design
Group Assignement
- actuate and automate your machine
- document the group project and your individual contribution
Okay, the last week about the mechanical design my task was to design the chassis that had welcome all of the different part of the machine. Then this week, basically my task is to design and code the mother board that will be orchestrate how and when work the other boards.
Here this is a little skecth of the global electronic architcture of the machine.
Basically, the idea is to create our own communication protocole using the Serial communicaion. Also, the powering (12V and GND) of the differents parts pass through the connector that we created. Then we used a 6 pins (ISP type) connector, 2 pins are for the 12V, 2 pins are for the GND and 2 pins for TX and RX.
Design the electronic mother board
For this part the first thing to decide is what microcontroler we will be using.²
#define NB_STEP 8
byte mstart=98;
byte mstop=99;
byte mreceipt = 100;
byte mendtask = 101;
byte mready = 102;
byte adr_deco = 31;
byte adr_char = 11;
byte adr_pmp1 = 21;
byte adr_pmp2 = 22;
byte adr_mixverre = 41;
byte adr_mixspeed = 42;
byte debug = 92;
byte cocktail[1][9][4] ={{
{mstart,adr_deco,1,mstop}, //deco start
{mstart,adr_char,1,mstop}, //chariot pos 1
{mstart,adr_pmp1,50,mstop}, //pompe 1 quantité 50
{mstart,adr_char,2,mstop}, //chariot pos 2
{mstart,adr_pmp2,50,mstop}, //pompe 2 quantité 50
{mstart,adr_char,4,mstop}, //chariot pos 4
{mstart,adr_mixverre,2,mstop}, //mixeur verre taille 2
{mstart,adr_mixspeed,100,mstop}, //mixeur speed 100
{mstart,adr_deco,0,mstop} //deco stop
}};
byte dataBuffer[4];
byte databuffertest;
void setup() {
Serial.begin(9600);
}
void sendPacket(int i_cocktail, int i_state){
//send a packet byte by byte
int i_byte;
for (i_byte=0;i_byte<=3;i_byte++){
Serial.write(cocktail[i_cocktail][i_state][i_byte]);
}
}
void makeCocktail(int i_cocktail){
int i_state;
//start the recipe
for (i_state=0;i_state<=NB_STEP;i_state++){
int validation = 0; //0 = no validation packet received
while (validation == 0){
//Send a packet and wait for the validation packet, if not re-send a packet
sendPacket(i_cocktail, i_state);
delay(1500);
if (Serial.available()){Serial.readBytes(dataBuffer,4);}
if (dataBuffer[3] == mstop && dataBuffer[1]==cocktail[i_cocktail][i_state][1] && dataBuffer[2] == mreceipt){
validation = 1;
}
}
//Wait for the end task packet
while(Serial.available()==0){delayMicroseconds(1);}
if (Serial.available()){Serial.readBytes(dataBuffer,4);}
}
if (dataBuffer[3] == mstop && dataBuffer[1]==cocktail[i_cocktail][i_state][1] && dataBuffer[2] == mendtask){
i_state++;
}
}
void loop() {
int char_ready = 0 ;
//wait for the 2 ready packets
while (char_ready < 1){
//Serial.write(debug-1);
while(Serial.available()==0){delayMicroseconds(1);}
if (Serial.available()){Serial.readBytes(dataBuffer,4);}
if (dataBuffer[3] == mstop && (dataBuffer[1]==adr_char || dataBuffer[1]==adr_mixverre) && dataBuffer[2]==mready){
char_ready+=1;
//Serial.write(char_ready);
}
}
makeCocktail(0);
}
byte mstart=98;
byte mstop=99;
byte mreceipt = 100;
byte mendtask = 101;
byte mready = 102;
byte adr_deco = 31;
byte adr_char = 11;
byte adr_pmp1 = 21;
byte adr_pmp2 = 22;
byte adr_mixverre = 41;
byte adr_mixspeed = 42;
byte debug = 92;
byte cocktail[1][9][4] ={{
{mstart,adr_deco,1,mstop}, //deco start
{mstart,adr_char,1,mstop}, //chariot pos 1
{mstart,adr_pmp1,50,mstop}, //pompe 1 quantité 50
{mstart,adr_char,2,mstop}, //chariot pos 2
{mstart,adr_pmp2,50,mstop}, //pompe 2 quantité 50
{mstart,adr_char,4,mstop}, //chariot pos 4
{mstart,adr_mixverre,2,mstop}, //mixeur verre taille 2
{mstart,adr_mixspeed,100,mstop}, //mixeur speed 100
{mstart,adr_deco,0,mstop} //deco stop
}};
void makeCocktail(int i_cocktail){
int i_state;
//start the recipe
for (i_state=0;i_state<=NB_STEP;i_state++){
int validation = 0; //0 = no validation packet received
while (validation == 0){
//Send a packet and wait for the validation packet, if not re-send a packet
sendPacket(i_cocktail, i_state);
delay(1500);
if (Serial.available()){Serial.readBytes(dataBuffer,4);}
if (dataBuffer[3] == mstop && dataBuffer[1]==cocktail[i_cocktail][i_state][1] && dataBuffer[2] == mreceipt){
validation = 1;
}
}
//Wait for the end task packet
while(Serial.available()==0){delayMicroseconds(1);}
if (Serial.available()){Serial.readBytes(dataBuffer,4);}
}
if (dataBuffer[3] == mstop && dataBuffer[1]==cocktail[i_cocktail][i_state][1] && dataBuffer[2] == mendtask){
i_state++;
}
}