Please help me that how to control a robot coding

please help me ~ !
please help me about my arduno robot plat form that (a nano)

it's can't reset itself by interrupt or reset itself per 200 ms automatically.

in order to RUN(move) and LISTEN(receive command) at the same time!

sort by: active | newest | oldest
steveastrouk5 months ago

Initialise.

Loop

See if there is a new message.

If there is, process it

If there isn't for a long time, stop motors whatever is happening.

Handle motors.

If motor is on, increment counter.

If motor is on and counter is > timelimit, reset counter and turn off motor.

Jump to Loop

David_Lin (author)  steveastrouk5 months ago

yes, and this work like that i use timer multiPRG method.

i will try the counter method what you mentiond.

David_Lin (author) 4 months ago

i select it because of that I have use the Timer

To constract a new object as multiPRG.

It is just the same with using a counter to independent

Form the dead loops too !

And thank you.

rickharris5 months ago

I hate rats nest wiring - Undo everything and re wires it CAREFULLY.

Your program should be commented so you can easily see what part does what.

Break it down into individual elements and test each one separately.

Read my last post and follow it's advice.

David_Lin (author)  rickharris5 months ago
i surely done !
i have re-wired and test each part one by one
but still can not put all codes together.
and finally i write the void rst() to solve it.(not really)
just reboot the nano only.(this make system lag a lot)
David_Lin (author) 5 months ago

it will some kind like below:

{ initial IR, SERVO }

|

v

{ initial variable }

|

v

{read from IR RCVR}

|

v

main loop

###################

{case up,down,left,right}

direc == up {power the DC motor forward & ask SERVO turn to 90 degreed}

direc == down {power the DC motor backward}

direc == left {ask SERVO turn to 135 degreed}

direc == right{ask SERVO turn to 45 degreed

{final}

delay (1000) <-- need multi program here can't really do delay !?

stop DC motor

#################

|

v

clear IR buffer //initial for next rcvr data

|

v

call void rst() <because every 200ms need the next IR input ?

|

v

return to the main loop

iceng5 months ago

Do a flow chart..

steveastrouk5 months ago

You don't attempt to multi-task by resetting the processor !!!!

Show your code, and explain EXACTLY what you want to do.

David_Lin (author)  steveastrouk5 months ago

coz that i can't solve the CPU thing and i use the reset circuit and void rst()

i kn~o it's not OK, but i don't kn~o how. Please help me!

program below:

Timer multiPRG;

void setup()

{

Serial.begin(9600);

irrecv.enableIRIn(); // Start the receiver

for(int i = 0; i < 4 ; i++){

pinMode(pins[i], OUTPUT);

pinMode(4, OUTPUT);

multiPRG.every(330,scan);

}

}

void loop() {

if (irrecv.decode(&results)) {

Serial.println(results.value, HEX);

multiPRG.update();

irrecv.resume(); // Receive the next value

delay(600);

}

}

void scan(){

unsigned long d=0x0;

d=results.value;

if (d==0x7D7DBE41){turn_L();

multiPRG.update();

delay(100); rst();}

else if (d==0x7D7D7E81){turn_R();

//906F12ED

delay(100); rst();}

if (d==0x7D7DDE21){turn_U();

//

delay(100); }

else if (d==0x7D7D3EC1){turn_D();

//

delay(100); }

if (d==0x7D7D847B){turn_1(); delay(100); }

if (d==0x7D7D44BB){turn_2(); delay(100); rst();}

if (d==0x7D7DC43B){turn_3(); delay(100); }

if (d==0x7D7D24DB){turn_4(); delay(100); rst();}

if (d==0x7D7DA45B){turn_5(); delay(100); }

if (d==0x7D7D649B){turn_6(); delay(100); rst();}

if (d==0x7D7DE41B){turn_7(); delay(100); }

if (d==0x7D7D14EB){turn_8(); delay(100); rst();}

if (d==0x7D7D946B){turn_9(); delay(100); }

if (d==0x7D7D04FB){turn_0(); delay(100); }

//=========================================

multiPRG.update();

multiPRG.pulse(4,300,LOW);

}

void turn_L(){

multiPRG.pulse(pins[0],3000,HIGH);

multiPRG.pulse(pins[1],3000,HIGH);

Serial.print("3");

delay(1000);

// irsend.sendNEC(0x7D7DBE41, 32);

//multiPRG.pulse(pins[0],10,LOW);

}

void turn_R(){

multiPRG.pulse(pins[0],3000,HIGH);

multiPRG.pulse(pins[2],3000,HIGH);

Serial.print("A");

delay(1000);

// irsend.sendNEC(0x7D7D7E81, 32);

//multiPRG.pulse(pins[0],10,LOW);

}

void turn_U(){

multiPRG.pulse(pins[0],3000,HIGH);

Serial.println("Up");

// irsend.sendNEC(0x7D7DDE21, 32);

delay(1000);

}

void turn_D(){

multiPRG.pulse(pins[2],1000,LOW);

Serial.println("Down");

// irsend.sendNEC(0x7D7D3EC1, 32);

delay(1000);

}

void turn_VU(){

multiPRG.pulse(pins[2],1000,LOW);

Serial.println("VOL_Up");

// irsend.sendNEC(0x7D7D6C93, 32);

delay(1000);

}

void turn_VD(){

multiPRG.pulse(pins[2],1000,LOW);

Serial.println("VOL_Down");

// irsend.sendNEC(0x7D7DEC13, 32);

delay(1000);

}

void turn_1(){

multiPRG.pulse(pins[2],1000,LOW);

Serial.println("1");

// irsend.sendNEC(0x7D7D847B, 32);

multiPRG.pulse(pins[0],300,LOW);

delay(1000);

}

void turn_2(){

multiPRG.pulse(pins[0],3000,HIGH);

Serial.println("2");

// irsend.sendNEC(0x7D7D44BB, 32);

multiPRG.pulse(pins[0],300,LOW);

delay(1000);

}

void turn_3(){

multiPRG.pulse(pins[2],1000,LOW);

Serial.println("3");

multiPRG.pulse(pins[0],300,LOW);

delay(1000);

}

void turn_4(){

multiPRG.pulse(pins[0],3000,HIGH);

multiPRG.pulse(pins[1],3000,HIGH);

Serial.println("3");

delay(1000);

}

void turn_5(){

multiPRG.pulse(pins[2],1000,LOW);

Serial.println("5");

// irsend.sendNEC(0x7D7DA45B, 32);

multiPRG.pulse(pins[0],300,LOW);

delay(1000);

}

void turn_6(){

multiPRG.pulse(pins[0],3000,HIGH);

multiPRG.pulse(pins[2],3000,HIGH);

Serial.print("A");

Serial.print("L");

delay(1000);

}

void turn_7(){

multiPRG.pulse(pins[2],1000,LOW);

Serial.println("7");

// irsend.sendNEC(0x7D7DE41B, 32);

multiPRG.pulse(pins[0],300,LOW);

delay(1000);

}

void turn_8(){

multiPRG.pulse(pins[3],3000,HIGH);

Serial.println("8");

multiPRG.pulse(pins[3],3000,HIGH);

delay(1000);

}

void turn_9(){

multiPRG.pulse(pins[2],1000,LOW);

Serial.println("9");

// irsend.sendNEC(0x7D7D946B, 32);

multiPRG.pulse(pins[0],300,LOW);

delay(1000);

}

void turn_0(){

multiPRG.pulse(pins[2],1000,LOW);

Serial.println("0");

// irsend.sendNEC(0x7D7D04FB, 32);

multiPRG.pulse(pins[0],300,LOW);

delay(1000);

}

void turn_PD(){

Serial.println("Power_01");

// irsend.sendNEC(0x7D7D0EF1, 32);

delay(1000);

}

void rst(){

multiPRG.update();

digitalWrite(4,HIGH);

delay(20);

digitalWrite(4,LOW);

delay(300);

}

David,, it's not even clear what root want to do, or what hardware you have.
Slow down
Start from scratch
What are you trying to do ?
What have you got to do it with ?

Steve
David_Lin (author)  steveastrouk5 months ago

hardware : tiny robot platform with nano_part_4

DSC_0259.JPG
David_Lin (author)  steveastrouk5 months ago

once I tried use a reset circuit (hardware), and write a sub-program

output a pusle to reset the nano in ordered to reload the nano again.

At the vary beginning, I just construed a remote platform purel.

And then I modifying it into aTiny robot platform with nano later,

That carry with a servo motor and a DC motor on boarded which powered

by AAA battery.

So I got to write a program both controling IR and controlling servo motor

and controlling a DC motor at the same time.

That is why I use multi-PRG, and I need reset the nano from loopins.

rickharris5 months ago

1. Your asking a question with a long and complex answer.

2. You don't give enough information to allow us to help you.

3. What have YOU tired?

4. How skilled are you at programing.

https://www.instructables.com/id/Lets-Program-a-PI...

https://www.instructables.com/id/Starting-programm...

David_Lin (author)  rickharris5 months ago

once I tried use a reset circuit (hardware), and write a sub-program

output a pusle to reset the nano in ordered to reload the nano again.

Search Tiny robot platform with nano or search David_Lin .

Your doing things in the wrong order.

START

make a flow chart of the things you need the robot to do, in the right order. (see my instructable above)

translating this flow chart box by box into code is trivial BUT you will need to know how to code the computer your using.

If your problems stem fro a lack of coding experience then your going to have to take a step back and start with very simple things flash a few leds, read some simple sensors, until your happy you understand the basics of how to programme the micro.

NOTE you only really need a few commands to do vast amounts of programming - See my instructable above.

Sounds like you have started with something too complex for your skill level at the present.

At school it took me 8 hours of tuition to get students to the point where they could program their robot as a simple obstacle avoidance machine.

You can't afford to miss out the early learning.