![]() |
detecting your own alliance(C++)
This is something I was wondering about the other day--is there a way for robots to determine what alliance they are on from the field control? This seems like it would be rather necessary if you wanted to hunt down opposing robots during the autonomous period.
|
Re: detecting your own alliance(C++)
Quote:
|
Re: detecting your own alliance(C++)
I was wondering that too, and since you asked the question, I thought I'd look. If you're using WPILib, the DriverStation class will tell you your alliance, at least it looks that way at first glance.
|
Re: detecting your own alliance(C++)
Quote:
That's <R18> F. I think you could put a switch on your robot which indicates alliance, and there may be something in code as well. |
Re: detecting your own alliance(C++)
The easy way is to put a switch on your bot. Program it in so that it tells what alliance you are on at startup. Example. You have a single position switch on the side of the bot. The people putting the bot in the crater set the switch for the blue alliance (switch closes the circuit on a digital I/O) the initialization code reads the state of that I/O and stores it in a variable called bool alliance (1 for blue, 0 for red). I hope this helps.
|
Re: detecting your own alliance(C++)
Quote:
Code:
switch (DriverStation::GetInstance()->GetAlliance()) { |
Re: detecting your own alliance(C++)
Weren't the '::' used for defining a function, not calling it? Like 'DriverStation::kRed' should be 'DriverStation.kRed'.
|
Re: detecting your own alliance(C++)
The double colon ("::") is a namespace operator. For example, one of the namespaces in C++ is the standard namespace, "std". So you could say,
"std::cout" etc since cout is in the std namespace. You could also say at the beginning of your program: "using namespace std;" This would allow you to implicitly refer to the std namespace. The dot operator is different. It allows you direct (non-pointer) access to data members of a class. For example, if you had some class Apple, you might have a call such as... "myApple.color" which could be red, yellow, greeen, etc. I don't fully understand jtdowney's code, since I am not at all familiar with the new interface, but this is the meaning of the dot operator versus double colon. |
Re: detecting your own alliance(C++)
Okay, thanks. Also, how do you distinguish between the light of each alliance. I always thought they were identical. If that's true, make sure your camera is pointed forward at the beginning of the match and lock onto the first thing you see. It'll undoubtedly be an enemy robot. Then, never let it out of your sight. Autonomous is only 15s, so this should be fine.
|
Re: detecting your own alliance(C++)
Quote:
|
Re: detecting your own alliance(C++)
Couldn't you dect the other robot by the fact you you recieve there instructions but just ignore them since they arn't coded for IP
(that should work right, or it will let you know who is on the field with you) |
Re: detecting your own alliance(C++)
Quote:
|
Re: detecting your own alliance(C++)
Yeah, I initially missed that because it's not in the Reference Manual. At all. That's right folks, you can only find it in the Users Guide. Check page 78 for useful functions for autonomous. You can also check the battery voltage! That's useful...I guess...They really need to finish those manuals.
|
Re: detecting your own alliance(C++)
Quote:
|
Re: detecting your own alliance(C++)
Before the match, you have what's called a "constructor" period in the SimpleRobot.cpp template which MIGHT be able to be used to run code in disabled, but my sources haven't tried it yet. If you use the BuiltinDefaultCode.cpp template (iterative template), there's a class for disabled mode. Basically, constructor is the equivalent of Initialize() or IO_Initialization() of the PIC version of WPILib, except I think it runs more than once. Using the disabled mode period, you can run code whenever the robot is disabled, the controller is just introverted; you can read inputs and run code, but you cannot run motors or set outputs until you're enabled.
That being said, that period is the perfect time to figure out where you are and what you're doing with the camera right after the cRIO boots up. With the complexity of the control system this year, there is no reason for your processor to have downtime. You can always be reading a sensor or analyzing visual data to find out where your opponents are and where your alliance members are. That way you know where those robots are already, and can track them when they dart off at the beginning of autonomous and plot a projected course for their trailers to meet very nicely with your moon rocks flying through the air :D But seriously, do use the camera. |
Re: detecting your own alliance(C++)
If only just to take rad pictures.
|
Re: detecting your own alliance(C++)
Quote:
If you examine WPILib, the START_ROBOT_CLASS macro passes startRobotTask() a function that creates an object of your RobotBase derived class. Once it starts the robot task, it creates your object. This is only done once (or at least, only when FRC_UserProgram_StartupLibraryInit() is called). Strictly speaking, FRC_UserProgram_StartupLibraryInit (also defined in the START_ROBOT_CLASS macro) is more like Initialize() or IO_Initialization()... but of course it gets called before your task is created and its probably not a particularly great idea to use it. :) |
Re: detecting your own alliance(C++)
Inside the WPI library, look in the driverstation.cpp file.
Inside there, you'll find that there is a function to tell you what alliance you are on (also, there is one that will tell you what station you're plugged into, 1,2, or 3) Quote:
|
| All times are GMT -5. The time now is 13:41. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi