Go to Post At this point (after shipping the robot), I'm really looking forward to doing laundry, eating a square meal, and getting to bed at a reasonable hour. - Emily Pease [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 Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 01-29-2015, 06:02 PM
RobHammann RobHammann is offline
Registered User
FRC #5143
 
Join Date: Jan 2015
Location: Grand Rapids MN
Posts: 8
RobHammann is an unknown quantity at this point
Declaring DoubleSolonoid

I have been trying to get solenoids to work all day, everything I try kicks back an error

grabSolenoid = new DoubleSolenoid(1, 1, 1);

always says "grabSolenoid is not a class"

What is the proper way to declare and run double solenoids? The screensteps isn't helping.
Reply With Quote
  #2   Spotlight this post!  
Unread 01-29-2015, 06:59 PM
Jon Stratis's Avatar
Jon Stratis Jon Stratis is offline
Electrical/Programming Mentor
FRC #2177 (The Robettes)
Team Role: Mentor
 
Join Date: Feb 2007
Rookie Year: 2006
Location: Minnesota
Posts: 3,720
Jon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond repute
Re: Declaring DoubleSolonoid

Try:

DoubleSolenoid grabSolenoid = new DoubleSolenoid(1, 1, 1);
__________________
2007 - Present: Mentor, 2177 The Robettes
LRI: North Star 2012-2016; Lake Superior 2013-2014; MN State Tournament 2013-2014, 2016; Galileo 2016; Iowa 2017
2015: North Star Regional Volunteer of the Year
2016: Lake Superior WFFA
Reply With Quote
  #3   Spotlight this post!  
Unread 02-02-2015, 10:48 AM
RobHammann RobHammann is offline
Registered User
FRC #5143
 
Join Date: Jan 2015
Location: Grand Rapids MN
Posts: 8
RobHammann is an unknown quantity at this point
Re: Declaring DoubleSolonoid

Quote:
Originally Posted by Jon Stratis View Post
Try:

DoubleSolenoid grabSolenoid = new DoubleSolenoid(1, 1, 1);
Could not convert '(operator new(104u), (<statement>, ((DoubleSolenoid*) <anonymous>)))' from' 'DoubleSolenoid*' to 'DoubleSolenoid'
Reply With Quote
  #4   Spotlight this post!  
Unread 02-02-2015, 11:59 AM
GeeTwo's Avatar
GeeTwo GeeTwo is online now
Technical Director
AKA: Gus Michel II
FRC #3946 (Tiger Robotics)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Slidell, LA
Posts: 3,539
GeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond repute
Re: Declaring DoubleSolonoid

Oh, yeah, C++ forum...try:

DoubleSolenoid *grabSolenoid = new DoubleSolenoid(1, 1, 1);
Reply With Quote
  #5   Spotlight this post!  
Unread 02-02-2015, 12:13 PM
Jon Stratis's Avatar
Jon Stratis Jon Stratis is offline
Electrical/Programming Mentor
FRC #2177 (The Robettes)
Team Role: Mentor
 
Join Date: Feb 2007
Rookie Year: 2006
Location: Minnesota
Posts: 3,720
Jon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond repute
Re: Declaring DoubleSolonoid

Oops, my bad... The syntax is almost identical between java and c++, expert for that annoying *. I really hate dealing with punters in c++!

They issue you were having was that you hadn't declared your variable before assuming it, so the compiler didn't know what "grabSolenoid" was. By adding the class in front, you're telling the compiler what that is.
__________________
2007 - Present: Mentor, 2177 The Robettes
LRI: North Star 2012-2016; Lake Superior 2013-2014; MN State Tournament 2013-2014, 2016; Galileo 2016; Iowa 2017
2015: North Star Regional Volunteer of the Year
2016: Lake Superior WFFA
Reply With Quote
  #6   Spotlight this post!  
Unread 02-02-2015, 12:27 PM
one_each one_each is offline
Registered User
FRC #4057 (KB Bots)
Team Role: Mentor
 
Join Date: Jun 2012
Rookie Year: 2012
Location: Klamath Falls, Or
Posts: 25
one_each is an unknown quantity at this point
Re: Declaring DoubleSolonoid

Here is a bit of explenation.

Could not convert '(operator new(104u), (<statement>, ((DoubleSolenoid*) <anonymous>)))' from' 'DoubleSolenoid*' to 'DoubleSolenoid'

The bolded parts are the important notes. Note the asterisk (or 'star') in the from and also note that it is missing in the to.

The new operator creates a new version of the class (DoubleSolenoid here) and returns a pointer to it. The asterisk (or 'star') indicates changes the type of grabSolenoid to a "pointer to DoubleSolenoid", thus making the types on both sides the same.

Pointers are one of the more confusing aspects of C/C++, however they are used everywhere. Remember, the pointer doesn't hold the data, it just points to where it is at. For classes, use the -> operator to access methods and fields from the pointer.
Reply With Quote
  #7   Spotlight this post!  
Unread 02-02-2015, 04:03 PM
RobHammann RobHammann is offline
Registered User
FRC #5143
 
Join Date: Jan 2015
Location: Grand Rapids MN
Posts: 8
RobHammann is an unknown quantity at this point
Re: Declaring DoubleSolonoid

Thanks, they do declare now, however...

Quote:
Originally Posted by one_each View Post
For classes, use the -> operator to access methods and fields from the pointer.

I really don't understand these pointers, when I try to set the solenoids using something like

grabSolenoid.set(DoubleSolenoid::kForward);

it says "request for member 'set' in '(((Robot*)this))->Robot::grabSolenoid', which is of pointer type 'DoubleSolenoid' (maybe you meant to use '->' ?)"

where do I put the ->?
Reply With Quote
  #8   Spotlight this post!  
Unread 02-02-2015, 04:14 PM
Steve Warner Steve Warner is offline
Controls / Programming
FRC #0234 (Cyber Blue)
Team Role: Mentor
 
Join Date: Feb 2006
Rookie Year: 2006
Location: Indiana
Posts: 41
Steve Warner is an unknown quantity at this point
Re: Declaring DoubleSolonoid

Try grabSolenoid->Set(DoubleSolenoid::kForward);
Reply With Quote
  #9   Spotlight this post!  
Unread 02-02-2015, 04:20 PM
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,112
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: Declaring DoubleSolonoid

Quote:
Originally Posted by RobHammann View Post
...using something like

grabSolenoid.set(DoubleSolenoid::kForward);

it says "request for member 'set' in '(((Robot*)this))->Robot::grabSolenoid', which is of pointer type 'DoubleSolenoid' (maybe you meant to use '->' ?)"

where do I put the ->?
You have declared grabSolenoid as a pointer to a double solenoid object. The member functions like Set() only work on an actual object. You need to dereference the pointer before you can call the function. The '->' is a small bit of syntax convenience that lets you dereference the pointer and do the equivalent of a '.' at the same time.

Just replace the '.' with '->' between the variable name and the function name.
Reply With Quote
  #10   Spotlight this post!  
Unread 02-02-2015, 05:08 PM
GeeTwo's Avatar
GeeTwo GeeTwo is online now
Technical Director
AKA: Gus Michel II
FRC #3946 (Tiger Robotics)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Slidell, LA
Posts: 3,539
GeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond repute
Re: Declaring DoubleSolonoid

Quote:
Originally Posted by Alan Anderson View Post
Just replace the '.' with '->' between the variable name and the function name.
Yes. obj_ptr->elt is equivalent to (*obj_ptr).elt . That is, look up the actual field or method within the object that obj_ptr points to.
Reply With Quote
  #11   Spotlight this post!  
Unread 02-02-2015, 06:23 PM
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,547
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: Declaring DoubleSolonoid

Quote:
Originally Posted by RobHammann View Post
grabSolenoid = new DoubleSolenoid(1, 1, 1);
Once you get the syntax correct, you'll want to make sure you're allocating unique channels, as you'll likely get a runtime error as written.
Reply With Quote
  #12   Spotlight this post!  
Unread 02-04-2015, 03:46 PM
RobHammann RobHammann is offline
Registered User
FRC #5143
 
Join Date: Jan 2015
Location: Grand Rapids MN
Posts: 8
RobHammann is an unknown quantity at this point
Re: Declaring DoubleSolonoid

Well it seems to have worked, I cant test it yet on actual solenoids, but it builds and deploys just fine
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 09:15 AM.

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