I am programming a robot, and I was wondering if there was code to cause the robot to stop whatever it was doing if a bumper was activated. Right now I am using a while loop but the combination of the slow processor, fast motors and complex functions executed while moving cause a delay that has damaged the robot when the bumpers were activated. Is there a way to get it to break out of whatever the program is doing, even in the middle of a function and jump to the bumper activation code?
wonderboyshp
0
Newbie Poster
Recommended Answers
Jump to PostHmm ... what about a return; statement in the middle of the function? Or you could use a break; statement to break out of a loop. For example,
void f(int x) { while (true) { move_forward(x); if (bumper) return; } return; }
Jump to PostMake a separate thread that monitors the bumper. When the bumper is activated, it calls some routine to immediately shut down the motors, or whatever.
Do you have to poll the bumper switches, or is there an interrupt of some sort? If you have to poll, you could have …
Jump to PostWell, if threads aren't supported by your IDE or the OS that is running on the robot, you're in a world of hurt. You could build your own thread management, but that is pretty advanced.
Is the problem with the current method that you aren't checking frequently enough, or …
All 10 Replies
Dani
4,084
The Queen of DaniWeb
Administrator
Featured Poster
Premium Member
Chainsaw
12
Posting Pro in Training
wonderboyshp
0
Newbie Poster
wonderboyshp
0
Newbie Poster
Chainsaw
12
Posting Pro in Training
wonderboyshp
0
Newbie Poster
DGmick
0
Newbie Poster
wonderboyshp
0
Newbie Poster
Chainsaw
12
Posting Pro in Training
wonderboyshp
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.