Go to Post A good teacher always needs to be a good student - Redhead Jokes [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #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
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Very Strange cRIO Crash Hunter1100 C/C++ 0 19-01-2009 16:39
HDD crash, need help recovering data! David Kelly IT / Communications 16 28-05-2007 23:25
PlasmaCam Crash Course Andrew Blair Technical Discussion 0 30-12-2005 21:48
Prom Night Crash Nate Edwards General Forum 5 28-05-2005 15:15
3dsmax5 Crash? yangotang Inventor 5 09-03-2003 21:17


All times are GMT -5. The time now is 13:39.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi