Go to Post Please don't act embarrassed if your designs didn't work out; join the club. You are learning and will get better every year. - Gary Dillard [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rating: Thread Rating: 3 votes, 5.00 average. Display Modes
  #1   Spotlight this post!  
Unread 15-12-2011, 15:10
CodeMonkey's Avatar
CodeMonkey CodeMonkey is offline
Self Proclaimed Ruler of Universe
AKA: Omar Issa Attar
FRC #0599 (Robodox)
Team Role: Programmer
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Los Angeles, CA
Posts: 20
CodeMonkey is an unknown quantity at this point
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.
Reply With Quote
  #2   Spotlight this post!  
Unread 15-12-2011, 23:08
xraymypanda's Avatar
xraymypanda xraymypanda is offline
Cowboy programmer
AKA: Chris M
FRC #0599 (RoboDox)
Team Role: Programmer
 
Join Date: Dec 2011
Rookie Year: 2011
Location: Granada Hills,CA
Posts: 82
xraymypanda has a spectacular aura aboutxraymypanda has a spectacular aura about
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.
Reply With Quote
  #3   Spotlight this post!  
Unread 16-12-2011, 19:55
xraymypanda's Avatar
xraymypanda xraymypanda is offline
Cowboy programmer
AKA: Chris M
FRC #0599 (RoboDox)
Team Role: Programmer
 
Join Date: Dec 2011
Rookie Year: 2011
Location: Granada Hills,CA
Posts: 82
xraymypanda has a spectacular aura aboutxraymypanda has a spectacular aura about
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
Attached Files
File Type: zip Robodox_2011_Chiropractor.zip (2.86 MB, 91 views)
Reply With Quote
  #4   Spotlight this post!  
Unread 16-12-2011, 22:45
WizenedEE's Avatar
WizenedEE WizenedEE is offline
Registered User
AKA: Adam
FRC #3238 (Cyborg Ferrets)
Team Role: Leadership
 
Join Date: Jan 2011
Rookie Year: 2010
Location: Anacortes, WA
Posts: 395
WizenedEE is a name known to allWizenedEE is a name known to allWizenedEE is a name known to allWizenedEE is a name known to allWizenedEE is a name known to allWizenedEE is a name known to all
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?
Reply With Quote
  #5   Spotlight this post!  
Unread 16-12-2011, 23:21
xraymypanda's Avatar
xraymypanda xraymypanda is offline
Cowboy programmer
AKA: Chris M
FRC #0599 (RoboDox)
Team Role: Programmer
 
Join Date: Dec 2011
Rookie Year: 2011
Location: Granada Hills,CA
Posts: 82
xraymypanda has a spectacular aura aboutxraymypanda has a spectacular aura about
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.
__________________

2011: Head Scout
2012: (figure)Head Programmer
2013: Head Programmer, Chief Strategist, Outreach Executive, and Driver
Reply With Quote
  #6   Spotlight this post!  
Unread 17-12-2011, 02:03
WizenedEE's Avatar
WizenedEE WizenedEE is offline
Registered User
AKA: Adam
FRC #3238 (Cyborg Ferrets)
Team Role: Leadership
 
Join Date: Jan 2011
Rookie Year: 2010
Location: Anacortes, WA
Posts: 395
WizenedEE is a name known to allWizenedEE is a name known to allWizenedEE is a name known to allWizenedEE is a name known to allWizenedEE is a name known to allWizenedEE is a name known to all
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]);
}
I didn't have to rewrite any functions to avoid using new, so I don't really know what you're getting at. I'm just wondering if it's that people don't teach this method (why?) or if there's actually a good reason for it.
Reply With Quote
  #7   Spotlight this post!  
Unread 17-12-2011, 09:59
xraymypanda's Avatar
xraymypanda xraymypanda is offline
Cowboy programmer
AKA: Chris M
FRC #0599 (RoboDox)
Team Role: Programmer
 
Join Date: Dec 2011
Rookie Year: 2011
Location: Granada Hills,CA
Posts: 82
xraymypanda has a spectacular aura aboutxraymypanda has a spectacular aura about
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.
__________________

2011: Head Scout
2012: (figure)Head Programmer
2013: Head Programmer, Chief Strategist, Outreach Executive, and Driver
Reply With Quote
  #8   Spotlight this post!  
Unread 17-12-2011, 10:22
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,043
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Team 599 Robodox - 2011 Logomotion Code


Quote:
Originally Posted by xraymypanda View Post
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.
Can you please explain why pointers make the digital sensors refresh properly?



Reply With Quote
  #9   Spotlight this post!  
Unread 17-12-2011, 13:41
xraymypanda's Avatar
xraymypanda xraymypanda is offline
Cowboy programmer
AKA: Chris M
FRC #0599 (RoboDox)
Team Role: Programmer
 
Join Date: Dec 2011
Rookie Year: 2011
Location: Granada Hills,CA
Posts: 82
xraymypanda has a spectacular aura aboutxraymypanda has a spectacular aura about
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.
__________________

2011: Head Scout
2012: (figure)Head Programmer
2013: Head Programmer, Chief Strategist, Outreach Executive, and Driver
Reply With Quote
  #10   Spotlight this post!  
Unread 17-12-2011, 16:28
WizenedEE's Avatar
WizenedEE WizenedEE is offline
Registered User
AKA: Adam
FRC #3238 (Cyborg Ferrets)
Team Role: Leadership
 
Join Date: Jan 2011
Rookie Year: 2010
Location: Anacortes, WA
Posts: 395
WizenedEE is a name known to allWizenedEE is a name known to allWizenedEE is a name known to allWizenedEE is a name known to allWizenedEE is a name known to allWizenedEE is a name known to all
Re: Team 599 Robodox - 2011 Logomotion Code

Quote:
Originally Posted by xraymypanda View Post
If I recall correctly, pointers are constructed when the code is first called then destructed when they are no longer needed.
Objects allocated with new are only destructed when delete is called on them. Statically allocated objects act essentially this way, though.

Quote:
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.
The constructor? That's only called when FRC_UserProgram_StartupLibraryInit() is called (defined in the START_ROBOT_CLASS macro) and never again.

Quote:
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.
I'm not sure what you mean by this. The copy constructor is disabled in SensorBase, which is inherited by all of the sensor classes, and new is only called in your class's constructor.

Quote:
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.
Do you have a source for that? I didn't think there was any difference between dynamically and statically allocated objects functionally.
Reply With Quote
  #11   Spotlight this post!  
Unread 17-12-2011, 16:50
xraymypanda's Avatar
xraymypanda xraymypanda is offline
Cowboy programmer
AKA: Chris M
FRC #0599 (RoboDox)
Team Role: Programmer
 
Join Date: Dec 2011
Rookie Year: 2011
Location: Granada Hills,CA
Posts: 82
xraymypanda has a spectacular aura aboutxraymypanda has a spectacular aura about
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.
__________________

2011: Head Scout
2012: (figure)Head Programmer
2013: Head Programmer, Chief Strategist, Outreach Executive, and Driver
Reply With Quote
  #12   Spotlight this post!  
Unread 17-12-2011, 18:11
WizenedEE's Avatar
WizenedEE WizenedEE is offline
Registered User
AKA: Adam
FRC #3238 (Cyborg Ferrets)
Team Role: Leadership
 
Join Date: Jan 2011
Rookie Year: 2010
Location: Anacortes, WA
Posts: 395
WizenedEE is a name known to allWizenedEE is a name known to allWizenedEE is a name known to allWizenedEE is a name known to allWizenedEE is a name known to allWizenedEE is a name known to all
Re: Team 599 Robodox - 2011 Logomotion Code

Quote:
Originally Posted by xraymypanda View Post
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.
Oh okay, it's just been something I've been wondering about for a while.
Reply With Quote
  #13   Spotlight this post!  
Unread 18-12-2011, 09:25
byteit101's Avatar
byteit101 byteit101 is offline
WPILib maintainer (WPI)
AKA: Patrick Plenefisch
no team (The Cat Attack (Formerly))
Team Role: Programmer
 
Join Date: Jan 2009
Rookie Year: 2009
Location: Worcester
Posts: 699
byteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of light
Re: Team 599 Robodox - 2011 Logomotion Code

Quote:
Originally Posted by WizenedEE View Post
Do you have a source for that? I didn't think there was any difference between dynamically and statically allocated objects functionally.
There can be. If you have a base class with virtual function DoStuff(), the generic pointer base* will call derivitives DoStuff(), but a static base will call its own DoStuff.
ex:
PHP Code:
class base {
    
virtual void DoStuff(){
        
cout<<"in base"<<endl;
    }
}
class 
deriv : public base {
    
virtual void DoStuff(){
        
cout<<"in deriv"<<endl;
    }
}

basebaseptr = new base(); //dynamic
base basestatic base(); //static
basederivptr = new deriv(); //dynamic
base derivstatic deriv(); //static

baseptr->DoStuff(); //==> in base
basestatic.DoStuff(); //==> in base
derivptr->DoStuff(); //==> in deriv
derivstatic.DoStuff(); //==> in base 
__________________
Bubble Wrap: programmers rewards
Watchdog.Kill();
printf("Watchdog is Dead, Celebrate!");
How to make a self aware robot: while (∞) cout<<(sqrt(-∞)/-0);
Previously FRC 451 (The Cat Attack)
Now part of the class of 2016 at WPI & helping on WPILib

Last edited by byteit101 : 18-12-2011 at 09:27.
Reply With Quote
  #14   Spotlight this post!  
Unread 18-12-2011, 21:21
Redneck's Avatar
Redneck Redneck is offline
Hacker Hick
AKA: Jamie (2.0) Moran
FRC #0599 (Robodox)
Team Role: Engineer
 
Join Date: Aug 2004
Rookie Year: 2004
Location: California
Posts: 90
Redneck is just really niceRedneck is just really niceRedneck is just really niceRedneck is just really nice
Send a message via AIM to Redneck
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.
__________________


Which badges can you claim?
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 12:23.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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