Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Status
Not open for further replies.

mohdhidayat

Newbie level 3
slam robot

hi guys. i am currently doing my final year project which is s.l.a.m robot. using ultrasonic sensor and i want to ask something on sensor unit. i am having some problems with sensor coding. the question is can i use switch...case looping to make the sensor move the robot, it is because when using if else the robot can move properly. hopefully someone can help me.

slam with ultrasonic

Some clarification required in order for us to help:

- Which ultrasonic "sensor unit" are you using?

- You can certain use a switch-case statement (from a software engineering logic perspective) to decide what the robot should do when an external sensor is triggered (rather than using interrupts for example) - can you post an example of the code that you're having difficulty with?

slam robots

hi mate, sorry got many work to do, here i post the coding. maybe it easy for me to do if...else looping.

Code:
void ultrasonic(void)
{
int distance;
// variable for distance measuring
char n=1;
// index for indicat mode
while(1)
// loop forever
{
distance = result;
if (distance >40)
// check if distance more than 40
{
forward();
SPEEDL = 250;
SPEEDR = 250;
}
else if (distance >30)
{
forward();
SPEEDL = 240;
SPEEDR = 240;
}
else if (distance >20)
{
stop();
delay(1000);
left();
}
// then stop
else
// else, distance less than 20
{
backward();
// then backward with medium speed and on the buzzer
SPEEDL = 250;
SPEEDR = 250;
}
}

while(1)
{
distance1 = result;
if (distance >40)
// check if distance more than 40
{
left();
SPEEDL = 200;
SPEEDR = 100;
}
else if (distance >30)
{
left();
SPEEDL = 150;
SPEEDR = 80;
}
else if (distance >20)
{
stop();
delay(1000);
right();
}

}

while(1)
{
distance2 = result;
if (distance >40)
// check if distance more than 40
{
right();
SPEEDL = 100;
SPEEDR = 200;
}
else if (distance >30)
{
right();
SPEEDL = 80;
SPEEDR = 150;
}
else if (distance >20)
{
stop();
delay(1000);

}

}
}

so can i do like this, guide me please

slam robotics

Code:
static void interrupt isr(void)
{
if (TMR0IF) // TMR0 is overflow
{
TMR0IF = 0; // clear flag bit
To +=0x100; // count number of
TMR0 overflow ( make it to 16bit TMR)
}
if(RBIF) // there is change bit
on RB4-RB7
{
RBIF = 0; //
____
if (RB4) // Rb4 is 1 mean is
rising form 0 __|
{
TMR0 = 0; // clear all counter
involved, start new count for period of RB4 high
To = 0;
}
//
___
else TH = TMR0 + To; // RB4 is 0 mean is falling form 1
|_____ // save TH, RB4 high period
}
if(RCIF)
{
RCIF = 0; // clear flag bit
if (RCREG == 'R') data[i=0]= RCREG; // check if start byte
'R' is met
else if (RCREG == 100) data[i=0]= RCREG; // check if start byte
'd'(decimal 100) is met
if ((data[0] == 'R'))data [i++] = RCREG; // save the data in data
array
if (i>4) i = 4;
// if the data array reached max, set the index to 4
}
}

can someone explain to me why this is happen. as i know, my senior said that the interupt coding is all right. i'm using mplab and hitech compiler doing this project. could someone help me

here is the error
Code:
Error   [195] G:\Documents and Settings\admin\Desktop\test.c; 59.6 expression syntax
Error   [222] G:\Documents and Settings\admin\Desktop\test.c; 59.28 binary digit expected
Error   [312] G:\Documents and Settings\admin\Desktop\test.c; 60.1 ";" expected
Error   [192] G:\Documents and Settings\admin\Desktop\test.c; 62.1 undefined identifier "on"
Error   [195] G:\Documents and Settings\admin\Desktop\test.c; 62.4 expression syntax
Error   [192] G:\Documents and Settings\admin\Desktop\test.c; 66.0 undefined identifier "____"
Error   [312] G:\Documents and Settings\admin\Desktop\test.c; 66.1 ";" expected
Error   [192] G:\Documents and Settings\admin\Desktop\test.c; 70.1 undefined identifier "involved"
Error   [192] G:\Documents and Settings\admin\Desktop\test.c; 70.11 undefined identifier "start"
Error   [195] G:\Documents and Settings\admin\Desktop\test.c; 70.17 expression syntax
Warning [374] G:\Documents and Settings\admin\Desktop\test.c; 75.1 missing basic type; int assumed
Error   [314] G:\Documents and Settings\admin\Desktop\test.c; 75.1 ";" expected
Error   [285] G:\Documents and Settings\admin\Desktop\test.c; 76.1 no identifier in declaration
Warning [374] G:\Documents and Settings\admin\Desktop\test.c; 76.1 missing basic type; int assumed
Error   [314] G:\Documents and Settings\admin\Desktop\test.c; 76.1 ";" expected
Error   [285] G:\Documents and Settings\admin\Desktop\test.c; 78.1 no identifier in declaration
Warning [374] G:\Documents and Settings\admin\Desktop\test.c; 78.1 missing basic type; int assumed
Error   [314] G:\Documents and Settings\admin\Desktop\test.c; 78.1 ";" expected
Error   [285] G:\Documents and Settings\admin\Desktop\test.c; 81.1 no identifier in declaration
Warning [374] G:\Documents and Settings\admin\Desktop\test.c; 81.1 missing basic type; int assumed
Error   [314] G:\Documents and Settings\admin\Desktop\test.c; 81.1 ";" expected
Error   [285] G:\Documents and Settings\admin\Desktop\test.c; 82.1 no identifier in declaration
Warning [374] G:\Documents and Settings\admin\Desktop\test.c; 82.1 missing basic type; int assumed
Error   [314] G:\Documents and Settings\admin\Desktop\test.c; 82.1 ";" expected
Error   [285] G:\Documents and Settings\admin\Desktop\test.c; 84.1 no identifier in declaration
Warning [374] G:\Documents and Settings\admin\Desktop\test.c; 84.1 missing basic type; int assumed
Error   [314] G:\Documents and Settings\admin\Desktop\test.c; 84.1 ";" expected
Advisory[1] too many errors (21)

thanks

Status
Not open for further replies.