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
369 robot code.txt (10.3 KB)
369 robot code.txt (10.3 KB)
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.
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!
I got the same Errors as a cpp file
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
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).
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]
:o That is what programming in Java 24/7 does to your mind. I almost forgot about that.
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.
incorrect information
[spoiler]
Here’s what I noticed at a quick glance in the constructor’s initialization list:
Carriage_motor(new Victor(4)),
Elevator_motor(new Victor(3)),
These are defined earlier as:
Victor *Elevator_motor;
Victor *Carriage_motor;
I believe you should have instead:
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.[/spoiler]
This is a situation where it would be useful to post the console output. The debugger would also be a valuable tool to use.
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.
:ahh: That’s right, and I was not even thinking about that. Good catch. My previous post was incorrect.