2

Author Topic: Differential Drive Robot - state machine  (Read 1047 times)

0 Members and 1 Guest are viewing this topic.

Offline Crunchy TheoryTopic starter

  • Full Member
  • ***
  • Posts: 80
  • Helpful? 0
  • "Well great is ok, but amazing would be great."
Differential Drive Robot - state machine
« on: September 19, 2011, 10:47:22 PM »
I finally finished the movement code for my tankbot. I took Webbot's example (http://www.societyofrobots.com/robotforum/index.php?topic=10754.0) and fleshed it out more. It works nicely for simple states like "wait", "forward", "reverse" but it gets messy if I use this technique to control each tread individually (like if I want the robot to curve by having one tread move faster than the other). So I basically have two giant switch statements, one for each tread, that are almost identical except all the variables have a "left"/"right" appended to the name. The only point in the code where the states converge is when poll for button.pressed (kill switch).

So, have you guys come up with a better technique for more advanced control of a differential drive robot? And for more context, I am planning to have the Axon receive serial commands from its companion ARM dev board that handles the computer vision. The serial commands will dictate how the robot will adjust its position based on what it's seeing. So maybe a state machine isn't even right for this application - I'm not sure.
The only way to top an upright screen, keyboard, and mouse is to eliminate the need for humans to touch a PC at all. Oh, hello there Mr. Robot... what would I like you to do, you ask?

Offline rbtying

  • Supreme Robot
  • *****
  • Posts: 452
  • Helpful? 31
Re: Differential Drive Robot - state machine
« Reply #1 on: September 20, 2011, 01:13:28 AM »
The way I usually implement this is to have states that utilize external variables:
Code: [Select]

enum { STOPPED, MOVE, FWD, REV } state;

switch (state) {
case REV:
  leftSpeed = rightSpeed = REV_SPEED;
  state = MOVE;
  break;
case FWD:
  leftSpeed = rightSpeed = FWD_SPEED;
  state = MOVE;
  break;
case STOPPED:
  leftSpeed = 0;
  rightSpeed = 0;
case MOVE:
  motors.setSpeed(leftSpeed, rightSpeed);
  break;
}

Serial commands can just send the leftSpeed and rightSpeed values over as 8-bit signed integers, and as long as the state is MOVE, the commands will be followed.

 


Get Your Ad Here

data_list