View Single Post
  #1   Spotlight this post!  
Unread 21-03-2009, 11:16
Shadow503's Avatar
Shadow503 Shadow503 is offline
printf("\r\n Moo!");
no team
Team Role: Human Player
 
Join Date: Mar 2007
Rookie Year: 1991
Location: na
Posts: 92
Shadow503 will become famous soon enoughShadow503 will become famous soon enough
Exclamation HELP: Robot Crash in Autonomous

I wrote some code for a simple table based autonomous mode, but whenever we ran it, the robot completely crashed (random motors will thrash around a split second before the thing finally dies).

I figure there must a seg fault caused by to the way I'm using a struct pointer, but I don't know enough C++ to get this coded the right way.

Anyone got a spare moment to look over the code? Thanks for your time!

auto_commands_2009.h:
Code:
//autonomous commands
#define AUTO_STOP			0
#define AUTO_DRIVE_4WHEEL	1
#define AUTO_DRIVE_PIVOT	2
#define AUTO_DRIVE_TANK		3
#define AUTO_DRIVE_CRAB		4


/*
struct commands
{
	int steer_mode;
	double time;
	double speed;
	double angle;
};
*/
struct Command
{
	int command;	//what command to run
	double param1;	//usually time
	double param2;	//usually speed
	double param3;	//usually angle
};

struct Command command_list_0[] = {	//DEFAULT - STAY STOPPED
		//   Command        parm 1     	parm 2   	parm 3  
		//	Steer mode		Time(Sec)	Speed		Angle
		{AUTO_STOP,       	0.0,        0.0,     	0.0}		
};

struct Command command_list_1[] = {

//   Command              parm 1     	parm 2   	parm 3  
//	Steer mode				Time(Sec)	Speed		Angle
{AUTO_DRIVE_4WHEEL,       	1.0,        10.0,     	0.0},
{AUTO_DRIVE_PIVOT,         	1.0,        10.0,     	10.0},
{AUTO_DRIVE_4WHEEL,         1.0,        10.0,     	10.0},
{AUTO_DRIVE_PIVOT,         1.0,        0.0,      	0.0},
{AUTO_STOP,          		1.0,       0.0,     	0.0}};
. . .
autonomous_2009.cpp:
Code:
/**
 * Call this method to drive
 * @param speed a double describing the speed		-15fps to +15fps
 */
void Autonomous::procTable(int AutoMode) {
	// TODO Finish autonomous code
	//		static INT32 autoSec = (INT32)GetClock() + 1;
	curTime+= TIME_PER_CYCLE;
	currentStateTime += TIME_PER_CYCLE;
	struct Command *currentCommand;
	
	//set the commandlist
	switch (AutoMode) {
	case AUTOMODE_0:		//Auton mode 0
		currentCommand = command_list_0;
		break;
	case AUTOMODE_1:		//Auton mode 0
		currentCommand = command_list_1;
		break;
	case AUTOMODE_2:		//Auton mode 0
		currentCommand = command_list_2;
		break;
	case AUTOMODE_3:		//Auton mode 0
		currentCommand = command_list_3;
		break;
	case AUTOMODE_4:		//Auton mode 0
		currentCommand = command_list_4;
		break;
	
	
	default:
		currentCommand = command_list_0;
		break;
	}
	
	//behave based on the current command
	switch (currentCommand[cur_command].command) {
	case AUTO_STOP:			//robot stopped
	default:		
		reqDriveSpeed = 0.0;				// Requested Drive speed
		reqAngle = 0.0;						// Requested steer angle
		reqDriveMode = STEER_MODE_4WHEEL;	// Requested Drive Mode
		if(currentCommand[cur_command].param1 != 0 && currentStateTime >= currentCommand[cur_command].param1 ) {	//time to move on to next state
			if(cur_command + 1 < sizeof(currentCommand)) {	//there is another command to run
				cur_command++;	//increment to next command
				currentStateTime = 0; //move on to next state
			}
		}		
		break;
	}
}
Reply With Quote