Go to Post Lesson learned, /always/ have a pick list! - Lil' Lavery [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

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 21-02-2011, 00:07
krudeboy51's Avatar
krudeboy51 krudeboy51 is offline
Only Programmer
AKA: kory
FRC #0369 (369)
Team Role: Programmer
 
Join Date: Mar 2010
Rookie Year: 2010
Location: brooklyn
Posts: 151
krudeboy51 is a glorious beacon of lightkrudeboy51 is a glorious beacon of lightkrudeboy51 is a glorious beacon of lightkrudeboy51 is a glorious beacon of lightkrudeboy51 is a glorious beacon of light
Send a message via AIM to krudeboy51
Programming Help!

Can anyone please help me, I wrote a code with some objects and for some reason when I deploy the code, the robot would connect for 5 seconds then disconnect and I would get an error on windriver that would ask if I would like to run the debugger can some one please look over this code to see my problem or error
Attached Files
File Type: txt 369 robot code.txt (10.3 KB, 46 views)
Reply With Quote
  #2   Spotlight this post!  
Unread 21-02-2011, 00:16
CodeMonkeyMatt CodeMonkeyMatt is offline
Registered User
FRC #2605
 
Join Date: Jan 2011
Rookie Year: 2008
Location: WA
Posts: 46
CodeMonkeyMatt is on a distinguished road
Re: Programming Help!

Simply put, you want to be creating classes in separate files, not structs in the same (you might be able to get away with putting them in the same file, not sure. I don't think it's a good idea either way though). Pick a simple WPILib class and structure your custom classes off that, using a cpp and header file. Then, you incorporate it with an #include statement, just like you would with one of the WPILib classes.

I only gave a quick glance through your code, and I'm facing my own programming troubles right now as well. I just needed a break so I came on here. Anyway, point being that I might be mistaken, or I might have missed another major bug, but I'd start there. If someone more knowledgable comes along, feel free to ignore my comments.

Last edited by CodeMonkeyMatt : 21-02-2011 at 00:17. Reason: Punctuation
Reply With Quote
  #3   Spotlight this post!  
Unread 21-02-2011, 08:22
krudeboy51's Avatar
krudeboy51 krudeboy51 is offline
Only Programmer
AKA: kory
FRC #0369 (369)
Team Role: Programmer
 
Join Date: Mar 2010
Rookie Year: 2010
Location: brooklyn
Posts: 151
krudeboy51 is a glorious beacon of lightkrudeboy51 is a glorious beacon of lightkrudeboy51 is a glorious beacon of lightkrudeboy51 is a glorious beacon of lightkrudeboy51 is a glorious beacon of light
Send a message via AIM to krudeboy51
Re: Programming Help!

I had it as a .h file and included it in the code before and but I would still get the same problem in which I would have to re-image the CRio just to get that code off. But i'll try it! Thanks!
Reply With Quote
  #4   Spotlight this post!  
Unread 22-02-2011, 14:06
krudeboy51's Avatar
krudeboy51 krudeboy51 is offline
Only Programmer
AKA: kory
FRC #0369 (369)
Team Role: Programmer
 
Join Date: Mar 2010
Rookie Year: 2010
Location: brooklyn
Posts: 151
krudeboy51 is a glorious beacon of lightkrudeboy51 is a glorious beacon of lightkrudeboy51 is a glorious beacon of lightkrudeboy51 is a glorious beacon of lightkrudeboy51 is a glorious beacon of light
Send a message via AIM to krudeboy51
Re: Programming Help!

I got the same Errors as a cpp file
Reply With Quote
  #5   Spotlight this post!  
Unread 22-02-2011, 18:32
wireties's Avatar
wireties wireties is offline
Principal Engineer
AKA: Keith Buchanan
FRC #1296 (Full Metal Jackets)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2004
Location: Rockwall, TX
Posts: 1,170
wireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond repute
Send a message via AIM to wireties
Re: Programming Help!

I'd like to help but that Elevator_Mechanism structure is crazy looking. It makes things hard to follow. Why did you not setup a class? I recommend you undeploy your code, reboot the cRio and use the "Debug Kernel Task" method to step through the code.

Does it really run for 5 seconds? If it runs for 5 seconds I doubt iyou have any memory or resource conflict errors. Are you petting the watchdog timer? Are your functions returning control where they should?

HTH

Last edited by wireties : 22-02-2011 at 18:39.
Reply With Quote
  #6   Spotlight this post!  
Unread 22-02-2011, 18:42
davidthefat davidthefat is offline
Alumni
AKA: David Yoon
FRC #0589 (Falkons)
Team Role: Alumni
 
Join Date: Jan 2011
Rookie Year: 2010
Location: California
Posts: 792
davidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud of
Re: Programming Help!

Memory leak? You have to be really careful when using malloc. That is if you don't know what you are doing, just use "new". You never freed your allocated data.

Add:
free(Elevator_heights);
after that for loop

edit: my analogy I like to use is like feeding a kid a whole bunch of food and not letting him poop afterwards. So that stays inside of him until you let him poop or he dies (the program exits).
__________________
Do not say what can or cannot be done, but, instead, say what must be done for the task at hand must be accomplished.

Last edited by davidthefat : 22-02-2011 at 18:51.
Reply With Quote
  #7   Spotlight this post!  
Unread 23-02-2011, 11:06
jwakeman jwakeman is offline
Registered User
FRC #0063 (Red Barons)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2010
Location: 16510
Posts: 182
jwakeman is just really nicejwakeman is just really nicejwakeman is just really nicejwakeman is just really nicejwakeman is just really nice
Re: Programming Help!

you have to be just as careful whether your using new or malloc. maybe even a little more careful when using new because then you have to choose correctly between delete and delete[]
Reply With Quote
  #8   Spotlight this post!  
Unread 23-02-2011, 18:35
davidthefat davidthefat is offline
Alumni
AKA: David Yoon
FRC #0589 (Falkons)
Team Role: Alumni
 
Join Date: Jan 2011
Rookie Year: 2010
Location: California
Posts: 792
davidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud of
Re: Programming Help!

Quote:
Originally Posted by jwakeman View Post
you have to be just as careful whether your using new or malloc. maybe even a little more careful when using new because then you have to choose correctly between delete and delete[]
That is what programming in Java 24/7 does to your mind. I almost forgot about that.
__________________
Do not say what can or cannot be done, but, instead, say what must be done for the task at hand must be accomplished.
Reply With Quote
  #9   Spotlight this post!  
Unread 23-02-2011, 22:17
MattD's Avatar
MattD MattD is offline
Registered User
AKA: Matthew Douglas
FRC #0228 (GUS Robotics)
Team Role: Alumni
 
Join Date: Feb 2006
Rookie Year: 2005
Location: Indianapolis, IN
Posts: 185
MattD is a splendid one to beholdMattD is a splendid one to beholdMattD is a splendid one to beholdMattD is a splendid one to beholdMattD is a splendid one to beholdMattD is a splendid one to beholdMattD is a splendid one to behold
Send a message via AIM to MattD
Re: Programming Help!

Quote:
Originally Posted by davidthefat View Post
Add:
free(Elevator_heights);
after that for loop
I'm not sure why this would be freed at after that for loop. It looks like there are other functions that want to access that array later on. It should be freed somewhere else (perhaps a destructor), but I don't think that this is the source of the problem. It appears it's only called at most twice during the program's run before it crashes.

As mentioned already, that Elevator_Mechanism structure is very strange looking. It's difficult to follow, so I can't say for sure whether or not that part would work.

Spoiler for incorrect information:

Here's what I noticed at a quick glance in the constructor's initialization list:
Code:
Carriage_motor(new Victor(4)),
Elevator_motor(new Victor(3)),
These are defined earlier as:
Code:
Victor *Elevator_motor;
Victor *Carriage_motor;
I believe you should have instead:
Code:
Carriage_motor(3),
Elevator_motor(4),
This is because the constructor for Victor expects an int with the value of a PWM port, and instead you're passing a pointer to a Victor. Since there are checks to make sure a valid PWM channel number is provided, I'd expect an IndexOutOfRange ("Allocating channel or module that is out of range") fatal error to be thrown by WPILib.

This is a situation where it would be useful to post the console output. The debugger would also be a valuable tool to use.
__________________
GUS Robotics Team 228

2010 WPI Engineering Inspiration Award
2010 WPI Regional Champions (Thanks 230 & 20!)
2010 CT VEX Champions
2010 CT VEX Innovate Award
2009 QCC VEX Champions
2009 CT Motorola Quality Award
2007 CT J&J Sportsmanship Award
2006 CT Best Website Award

Last edited by MattD : 24-02-2011 at 08:01.
Reply With Quote
  #10   Spotlight this post!  
Unread 24-02-2011, 00:41
CodeMonkeyMatt CodeMonkeyMatt is offline
Registered User
FRC #2605
 
Join Date: Jan 2011
Rookie Year: 2008
Location: WA
Posts: 46
CodeMonkeyMatt is on a distinguished road
Re: Programming Help!

Good catch on the constructors. Actually though, I think the whole lines for the Carriage motor and elevator motor before the "{" braces should be taken out. Since those are declared as pointers, you use the "name = new ClassName(args);" format in the actual constructor, which you were doing, but then commented out.

If you declared the objects as actual objects instead of as pointers (i.e. Victor Elevator_motor; Victor Arm_motor; instead of Victor *Elevator_motor; Victor *Arm_motor; ) then you would use the format described by MattD.

As always, I'm only a fallible student, so someone feel free to disprove me.

Last edited by CodeMonkeyMatt : 24-02-2011 at 00:42. Reason: Syntax turned into smile
Reply With Quote
  #11   Spotlight this post!  
Unread 24-02-2011, 07:55
MattD's Avatar
MattD MattD is offline
Registered User
AKA: Matthew Douglas
FRC #0228 (GUS Robotics)
Team Role: Alumni
 
Join Date: Feb 2006
Rookie Year: 2005
Location: Indianapolis, IN
Posts: 185
MattD is a splendid one to beholdMattD is a splendid one to beholdMattD is a splendid one to beholdMattD is a splendid one to beholdMattD is a splendid one to beholdMattD is a splendid one to beholdMattD is a splendid one to behold
Send a message via AIM to MattD
Re: Programming Help!

Quote:
Originally Posted by CodeMonkeyMatt View Post
Since those are declared as pointers, you use the "name = new ClassName(args);" format in the actual constructor, which you were doing, but then commented out.

If you declared the objects as actual objects instead of as pointers (i.e. Victor Elevator_motor; Victor Arm_motor; instead of Victor *Elevator_motor; Victor *Arm_motor; ) then you would use the format described by MattD.
That's right, and I was not even thinking about that. Good catch. My previous post was incorrect.
__________________
GUS Robotics Team 228

2010 WPI Engineering Inspiration Award
2010 WPI Regional Champions (Thanks 230 & 20!)
2010 CT VEX Champions
2010 CT VEX Innovate Award
2009 QCC VEX Champions
2009 CT Motorola Quality Award
2007 CT J&J Sportsmanship Award
2006 CT Best Website Award

Last edited by MattD : 24-02-2011 at 07:56. Reason: quoted previous post
Reply With Quote
Reply


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


All times are GMT -5. The time now is 03:07.

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