|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
Using multiple classes in java to control one pwm
So I'm trying to figure out how to do multiple classes. This is the strucuture of the classes, where everything in events is a system on the robot.
http://www.chiefdelphi.com/forums/at...5&d=1396919131 The problem is, I put all the pwm stuff in map, so when the second one runs it complains about that pwm already being assigned. How do I get around this? Here is the error I get, incase I misinterpreted it: Spoiler for blah:
|
|
#2
|
||||
|
||||
|
Re: Using multiple classes in java to control one pwm
Can you paste your map.java?
If at any point a conflict in PWM ports is detected your project will return an error and a stacktrace like the one you pasted. You will probably need to reassign the port in code, as well as move the physical cable itself on your Digital Sidecar. Last edited by NWChen : 08-04-2014 at 14:13. Reason: typo, "past" -> "paste" |
|
#3
|
|||
|
|||
|
If you declare a talon object in map.java, you can just make new variables in the two other classes that point to the existing object.
Ex: Talon motor = map.getMotor(); Or just map.motor if you make it public, but encapsulation. |
|
#4
|
||||
|
||||
|
Re: Using multiple classes in java to control one pwm
Quote:
Code:
Talon motor = new Motor(PWM_PORT_ON_DSC); |
|
#5
|
||||
|
||||
|
Re: Using multiple classes in java to control one pwm
Sorry, the one I was using as map was outputmap. I called it map in all the events though. (Map is inputmap, will go ahead and rename it.)
Spoiler for outputmap:
Also, how do I make it public so I don't have to write: Code:
import edu.wpi.first.wpilibj.templates.outputmap; //inside of class outputmap map=new outputmap(); |
|
#6
|
||||
|
||||
|
Re: Using multiple classes in java to control one pwm
Quote:
Code:
public class outputmap
{
//output
public static Talon leftdrive=new Talon(1);
public static Talon rightdrive=new Talon(2);
...
}
// Somewhere else in the code
Talon myMotor = outputmap.leftdrive;
|
|
#7
|
||||
|
||||
|
Re: Using multiple classes in java to control one pwm
Thanks, it worked perfectly. Doesn't seem to like multiple instances.
That is really weird, that you can access a static variable when you can't access a non-static one, I can see something like public/private/semiprivate where semiprivate is the same as current public and public is the same as current public static. I do come from python and javascript though, so not having types to variables must be weird here. |
|
#8
|
|||
|
|||
|
Quote:
So, outputmap x = new outputmap(); Static variables and methods, however, do not require this. Please correct me if anything I said is horribly wrong ![]() |
|
#9
|
||||
|
||||
|
Re: Using multiple classes in java to control one pwm
Quote:
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|