I was reading this book which talks about behavior base robotics. Since it uses IC for programming at some point it uses a function called startprocess(). After looking through the web I could not find how this function could translate in plain C. Or how to implement a simple two behavior in C
So here is two simple behavior, with it's arbitration system. I actually understand very well how this can work. The on thing that does not make sense is how would I start the behavior in C
//Cruise Behavior
int cru_trans = 0; //Translational rotation velocity
int cru_rot = 0; //Rotational velocity
int cru_act = 0; //Cruise active flag
int cru_def_vel = 100; //Default speed
void cruise(void){
while(1){
cru_act =1; //Cruise Always wants control
cru_trans = cru_def_vel; //Standard Velocity
cru_rot = 0; //Don't rotate
}
}
int av_trans = 0; //avoid translational velocity
int av_rot = 0; // avoid rotational velocity
int av_act = 0; // avoid active flag
int av_def_trans = 100; // avoid default translational velocity
int av_def_rot = 50; //avoid default rotational velocity
void avoid(void){
int ir_hit = 0; //Local variable for obstacle detection
while(1){
ir_hit = ir_detect(); //ir_detect returns which ir sensor sees something
if(ir_hit == 0){ //No detection
av_act = 0;
}
else if(ir_hit == 3){ //Detection Both side
av_act = 1;
av_rot = av_def_rot; //Arbitrary rotate left
av_trans = 0;
}
else{
av_act = 1; //Avoid wants control
av_trans = 0; //Don't move forward
av_rot = av_def_rot; //Rotate away
}
}
}
int mot_trans = 0;
int mot_rot = 0;
void motors(){
while(1){
drive(mot_trans,mot_rot);
}
void arbitrate(){
while(1){
if(av_act){
mot_trans = av_trans;
mot_rot = av_rot;
}
else if(cru_act){
mot_trans = cru_trans;
mot_rot = cru_rot;
}
else{
mot_trans = 0;
mot_rot = 0;
}
}
}
void main(){
start_process(avoid());
start_process(cruise());
start_process(motors());
start_process(arbitrate());
}