![]() |
|
#1
|
|||
|
|||
|
Team 67 have ported our 2007 Rack n' Roll teleoperated code to the Beta control system. We're working on porting our autonomous code, and you can see the beginnings of that in the attached files.
The 2007 Hot Bot is a six-wheel-center-drop tank drive with two CIMS. A four-bar linkage arm is driven by a single CIM. The "hand" at the arm end is driven by two motors to grab, release and tilt the tube. Driver control is achieved via two Logitech GamePads, one for tank-driving and one to operate the arm. One GamePad joystick can be used to manually operate the arm, and buttons 1, 2, 3 and 4 are used to move the arm to setpoints by means of PID control. Another GamePad joystick is used to operate the two hand motors. The hand motor direction can be changed by pressing one of the front GamePad buttons, so the Rack n' Roll tube can either be grabbed/released or tilted depending on motor phasing. The robot has a potentiometer to measure arm angle, a gyro, left and right-side encoders, and a Axis 206 camera that fits nicely into the 2007 CMUCam pan-tilt frame. Two C++ robot-programming classes were available to choose from -- a SimpleRobot and IterativeRobot. IterativeRobot works very much like the FRC code we've been using the past few years in that a master while-loop is used to repetatively execute our user-written code. For example when running the teleop code in the attached example, TeleopInit() is called once on entry, and then TeleopPeriodic() is called at a 10ms rate. Autonomous and disabled mode work the same way. SimpleRobot, on the other hand, does not run a master while-loop, so user-written-code is executed once sequentially. If you wanted to run part of your code repetatively -- to wait for something, for example -- you would use a loop within your code. Team 67 chose to use -- at least for now -- the IterativeRobot class because it is similar to what we've been using in past seasons. We thought it would be easier for us to implement quickly and also to explain to other teams. I won't try to explain more of the code right now -- I can probably do that best by answering questions if they arise. Dave D
__________________
FRC: HOT, Team 67, Mentor, C++ Beta Test Lead FLL: Dark Matter Dark Energy, Team 3069, Coach |
|
#2
|
|||
|
|||
|
Awesome!
I am so glad to finally see some C++ Code!!! |
|
#3
|
|||
|
|||
|
hallelujah!!
Finaly, some code I can read! MORE!!!!! O_O!!!!! I NEED MORE C++!!!! P.S Time for questionts: 1) Why use a pointer for almost all variables (when you create them)? Last edited by Bomberofdoom; 10-24-2008 at 03:27 AM. |
|
#4
|
|||
|
|||
|
Quote:
Those pointers you see declared are later initialized to point to C++ objects such as gamepads, drive motors, etc. The pointers allow you to later access the objects and perform operations on them (methods in C++ speak). For instance, declare a pointer to a "Victor" object: Victor *armMotor; Then intialize the pointer to the arm victor on PWM output 7: armMotor = new Victor(7); Then turn on the arm motor by using the Victor method "Set()": armMotor->Set(gamePad2->GetLeftY()); Cool, huh! Somebody with more C++ experience under their belt might need to chime in and help with my explanation. BTW, there are lots of non-pointer variables in there, too. Dave D
__________________
FRC: HOT, Team 67, Mentor, C++ Beta Test Lead FLL: Dark Matter Dark Energy, Team 3069, Coach |
|
#5
|
|||
|
|||
|
Thanks for posting this code! We're excited to use C++ this year so its great to see some actual examples.
How is the debugger support? Can you step through code running on the cRio? Can you inspect the values of variables? Print to a debug window on the driver station? Greg |
|
#6
|
|||
|
|||
|
Quote:
I can understand the idea of using a pointer, but from my expirence with OOP, you really don't have to. If it's possible, I'd like Team 67 to try to write the following instead of: Victor *ArmMotor; ArmMotor = new Victor(7); Like this: Victor ArmMotor = new Victor(7); It supposed to be the exact same thing, without the pointer(*) and doing the initialization the same time the ArmMotor object is defined. If it doesn't work, then I'll have to look further into this to see why. |
|
#7
|
|||
|
|||
|
Quote:
Code:
Victor ArmMotor(7); Code:
class HOT_Bot : public IterativeRobot
{
// Declare robot drive system variable
RobotDrive myRobot; // robot will use PWM 1-4 for drive motors
// Declare driver station object variable
DriverStation *ds; // driver station object
TrackingThreshold tdata; // image data for tracking
// Declare GamePad variables
GamePad gamePad1; // gamepad 1 (drive control)
GamePad gamePad2; // gamepad 2 (arm control)
// Declare drive motor variables
// PWM 1 and 2 are unused, we'll save them for a four-motor drivetrain
Victor leftDriveMotor; // left drive motor will be on PWM 3
Victor rightDriveMotor; // right drive motor will be on PWM 4
......
HOT_Bot(void)
: myRobot(1,2,3,4),
gamePad1(1),
gamePad2(2),
leftDriveMotor(3),
rightDriveMotor(4),
......
{
PRINTFDEBUG(("HotBot Constructor Started\n"));
// Acquire the Driver Station object
ds = DriverStation::GetInstance();
......
Thanks, Sam Last edited by sharrington; 10-24-2008 at 06:21 PM. Reason: Expand, add disclaimer, fix typo |
|
#8
|
|||
|
|||
|
Quote:
I can't really explain what happens while you write the code you wrote there sharrington, but you're technacly supposed to Allocate Memory for the ArmMotor object you create. That is done by using the "new" prefix. Accessing the memory is done by using a reference, which is done by using the pointer (*), therefor it's probablly the most right way to write the code like this: Victor *ArmMotor = new Victor(7); The best way to know is to ask the Beta teams currently using C++ to check these methods and give us back the response of the compiler (errors, built successfuly, robot crazyness or something). Last edited by Bomberofdoom; 10-24-2008 at 07:29 PM. Reason: Basic C++ fundamentals....Moderate programmer....My memory does not serve me well...-_-' |
|
#9
|
|||
|
|||
|
Quote:
Code:
ClassName varName (param1,param2,...); Code:
class ClassName {
public:
AnotherClassName varName; /* the member variable of type AnotherClassName */
ClassName() /* the ClassName constructor */
: varName(param1,param2,...) /* call the member variable's constructor */
{
/* stuff */
}
}
Quote:
Quote:
For more information on C++ and classes see http://www.cplusplus.com/doc/tutorial/ and cprogramming.com/tutorials/. Thanks, Sam Last edited by sharrington; 10-24-2008 at 07:09 PM. Reason: Add comments to code example |
|
#10
|
|||
|
|||
|
Sigh...I got used to using the "new" prefix that I totally forgot that this initialization is possible....
![]() Thanks for the refreshner, Sam. Good thing you're around to fix my mistakes. ![]() Oh boy, I can expect this to be an exciting year for everyone, messing up the code in the wrong way....
__________________
Team 2230 Programming sub-team Leader. Non-Beta Tester. C/C++ moderate programmer. Labview Programmer. FIRST ADDICT. |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|