|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools |
Rating:
|
Display Modes |
|
#1
|
||||
|
||||
|
Team 599 Robodox - 2011 Logomotion Code
Hey all,
This is our code for Logomotion. Feel free to take a look. Last edited by CodeMonkey : 15-12-2011 at 15:36. |
|
#2
|
||||
|
||||
|
Re: Team 599 Robodox - 2011 Logomotion Code
Ugh, looks like we forgot to attach the code
I suppose we will have to wait until at least tomorrow to grab the code and post it, sorry folks. |
|
#3
|
||||
|
||||
|
Re: Team 599 Robodox - 2011 Logomotion Code
Alright, now that I finally get a chance to post it, here is the Robodox-team 599 2011 Logomotion robot code, available for all.
Enjoy |
|
#4
|
||||
|
||||
|
Re: Team 599 Robodox - 2011 Logomotion Code
I've always been curious as to why teams use pointers and new rather than objects. Why did your team use dynamic memory allocation?
|
|
#5
|
||||
|
||||
|
Re: Team 599 Robodox - 2011 Logomotion Code
WizenedEE, most of what I have learned about coding has come from mentors, so correct me if I'm wrong. We used pointers and new to avoid virtual errors and rewrites and because of different inheritances in the library provided to us. In most cases, it was simply easier to create new, temporary copies of variables than to work around the code that we didn't write and didn't want to rewrite. I hope that answers your question.
|
|
#6
|
||||
|
||||
|
Re: Team 599 Robodox - 2011 Logomotion Code
Well, I'm pretty new to the WPILib, but this is what I would do.
Code:
class Fred2 : public SimpleRobot {
public:
Fred2();
~Fred2();
void Autonomous();
void OperatorControl();
private:
OperatorConsole opCon;
/*Drivetrain*/
CANJaguar frontLeftWheelMtr;
CANJaguar rearLeftWheelMtr;
CANJaguar frontRightWheelMtr;
CANJaguar rearRightWheelMtr;
RobotDrive drivetrain;
/*Arm*/
CANJaguar longArmMtr;
CANJaguar shortArmMtr;
CANJaguar wristMtr;
Relay clawRly;
DigitalInput clawClosedSwitch;
DigitalInput clawOpenedSwitch;
/*Deployer*/
Deployer deployer;
/*Flippers*/
Servo flipperReleaseServo;
};
Code:
Fred2::Fred2() :
/*Drivetrain*/
frontLeftWheelMtr(frontLeftWheelMtrDevNum),
rearLeftWheelMtr(rearLeftWheelMtrDevNum),
frontRightWheelMtr(frontRightWheelMtrDevNum),
rearRightWheelMtr(rearRightWheelMtrDevNum),
drivetrain(frontLeftWheelMtr, rearLeftWheelMtr,
frontRightWheelMtr, rearRightWheelMtr),
/*Arm*/
/*Motors*/
longArmMtr(longArmMtrDevNum),
shortArmMtr(shortArmMtrDevNum),
wristMtr(wristMtrDevNum),
clawRly(clawRlyChannel),
/*Sensors*/
clawClosedSwitch(digitalModuleSlot, clawClosedSwitchChannel),
clawOpenedSwitch(digitalModuleSlot, clawOpenedSwitchChannel),
/*Flippers*/
flipperReleaseServo(digitalModuleSlot, flipperReleaseServoChannel)
{ /*Init Code*/
drivetrain.SetInvertedMotor(RobotDrive::kFrontLeftMotor,
driveMotorInvert[0]);
drivetrain.SetInvertedMotor(RobotDrive::kRearLeftMotor,
driveMotorInvert[1]);
drivetrain.SetInvertedMotor(RobotDrive::kFrontRightMotor,
driveMotorInvert[2]);
drivetrain.SetInvertedMotor(RobotDrive::kRearRightMotor,
driveMotorInvert[3]);
}
|
|
#7
|
||||
|
||||
|
Re: Team 599 Robodox - 2011 Logomotion Code
I think we went with pointers in the functions where we would need to use digital sensors because of problems with the sensor maintaining its state and not refreshing properly. Other than that, I don't think there is any reason that you should not use objects in your code.
|
|
#8
|
||||
|
||||
|
Re: Team 599 Robodox - 2011 Logomotion Code
Quote:
|
|
#9
|
||||
|
||||
|
Re: Team 599 Robodox - 2011 Logomotion Code
If I recall correctly, pointers are constructed when the code is first called then destructed when they are no longer needed. The code is called upon three times, once when the robot first turns on, when autonomous begins, and finally when the tele-op period begins. With pointers, the values of the variables are reset to their original position because a new copy is constructed for autonomous and a new copy is constructed for teleop. Otherwise, as with an object, when tele-op begins, the state that the sensor was last left in will now be its zero state. This could cause problems with an automatic lift system using an encoder or with gyroscopes on the robot.
|
|
#10
|
||||
|
||||
|
Re: Team 599 Robodox - 2011 Logomotion Code
Quote:
Quote:
Quote:
Quote:
|
|
#11
|
||||
|
||||
|
Re: Team 599 Robodox - 2011 Logomotion Code
WizenedEE, you are correct in what you have stated, and to be honest, I don't quite remember why we went with pointers instead of objects. I don't have much C++ experience, just one season of FRC and I cannot for the life of me remember why we went with pointers.
|
|
#12
|
||||
|
||||
|
Re: Team 599 Robodox - 2011 Logomotion Code
Quote:
|
|
#13
|
||||
|
||||
|
Re: Team 599 Robodox - 2011 Logomotion Code
Quote:
ex: PHP Code:
Last edited by byteit101 : 18-12-2011 at 09:27. |
|
#14
|
||||
|
||||
|
Re: Team 599 Robodox - 2011 Logomotion Code
byteit101, you've perfectly described the exact situation I made the programmers on 599 use pointers. We derived our own classes for some of the sensors to implement some custom functionality. Yes, we could have still done everything with statically allocated objects but I wanted to give the students some exposure to working with pointers and dynamic allocation because that's something that a lot of people in my CS classes in college had trouble with.
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|