![]() |
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 commandsCode:
/** |
Re: HELP: Robot Crash in Autonomous
I'm not sure if this is the root of your problem, but I don't believe you are using structs properly, and I think it's strange the compiler didn't catch it. You only need the "struct" keyword before Command when you declare the struct. So, you don't need so say
Code:
struct Command command_list_0[] = { //DEFAULT - STAY STOPPEDCode:
Command command_list_0[] = { //DEFAULT - STAY STOPPEDThe only place you need the struct keyword is here, when you declare the struct: Code:
struct Command |
Re: HELP: Robot Crash in Autonomous
Thanks! I'll try that during the next build window!
|
Re: HELP: Robot Crash in Autonomous
If you're looping the Autonomous::procTable(int AutoMode), make sure to delete the *currentCommand pointer.
And if you're using WPILib, I fail to see the point for using structs... |
Re: HELP: Robot Crash in Autonomous
Quote:
This is at least part of the problem you are experiencing. "sizeof(currentCommand)" will not give the size of the commands array. sizeof evaluates at compile time to the size of a type, or, when used with a variable, the type of the variable. currentCommand's type is "struct Command *". So, the sizeof (regardless of which command table is chosen to have currentCommand point to) will always evaluate to the size of a struct Command pointer (probably 4). This could be greater than the actual size of your command table, causing your program to potentially walk off the end of an array. The easiest way to change this would be to add another command type that signifies the end of the command table. When your autonomous code sees that command as it processes the table, it knows it has reached the last entry. |
Re: HELP: Robot Crash in Autonomous
also if you do this
Code:
type *varname;you need to do this Code:
type *varname; |
Re: HELP: Robot Crash in Autonomous
Quote:
Code:
struct Command *currentCommand; |
| All times are GMT -5. The time now is 13:38. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi