Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   RELAY!! (http://www.chiefdelphi.com/forums/showthread.php?t=87375)

jhersh 05-11-2010 13:04

Re: RELAY!!
 
Quote:

Originally Posted by krudeboy51 (Post 979739)
Code:

myRobot(1, 2),
...                       
        {
...
                pair1 = new Victor(1);
                pair2 = new Victor(2);


This is the source of your error. You presumably (since you didn't actually show it) have a RobotDrive member called myRobot which uses PWM channels 1 and 2. You then create 2 Victors which use PWM channels 1 and 2. These 2 channels are already in use by your robot drive object.

Dave Scheck 05-11-2010 13:17

Re: RELAY!!
 
Thanks for the correction Joe. After reading through the WPILib code again, I see how this is being done and agree with what you said about the resources. I also see what you mean about my code example. With the realays and digitial i/o on the same slot, it doesn't make any difference to specify the slot number in this case. I went back and put my original post in a spoiler tag to prevent confusion yet still have my bad analysis still available to learn from.

So, back to the analysis of the original error. The error clearly states that a resource is being allocated that was already allocated. I saw that Alan just posted a good suggestion that I was going to suggest next. My other suggestion (somewhat related) was to make sure there were no other places in the code that create relays, speed controllers, or analog/digital inputs on channels that were already in use for that resource type.

Dave Scheck 05-11-2010 13:21

Re: RELAY!!
 
Quote:

Originally Posted by jhersh (Post 979757)
This is the source of your error. You presumably (since you didn't actually show it) have a RobotDrive member called myRobot which uses PWM channels 1 and 2. You then create 2 Victors which use PWM channels 1 and 2. These 2 channels are already in use by your robot drive object.

One thing to add on to this is that RobotDrive creates Jaguar objects on these channels. Based on the code it looks like you are using Victors.

You might want to look into using one of these two implementations of RobotDrive.
RobotDrive::RobotDrive(SpeedController *leftMotor, SpeedController *rightMotor, float sensitivity);
RobotDrive::RobotDrive(SpeedController &leftMotor, SpeedController &rightMotor, float sensitivity);

jhersh 06-11-2010 15:52

Re: RELAY!!
 
Quote:

Originally Posted by Dave Scheck (Post 979758)
My other suggestion (somewhat related) was to make sure there were no other places in the code that create relays, speed controllers, or analog/digital inputs on channels that were already in use for that resource type.

Very true. We only saw a small snippet of code and it's quite conceivable that other objects are constructed else where. Wouldn't it be nice if the error told you which allocation cause the reuse?


All times are GMT -5. The time now is 14:26.

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