|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
Re: Pointers and Tank Drive?
Brad - I understand the declarations are above (page 12), but the code on page 14 seems to be the combination of the snippets above. It would make sense that that would be the case. However, as I stated, the code on page 14 wouldn't compile because of the undeclared stick1 and stick2. If the original user copy/pasted the example verbatim, I believe that my explanation would explain the issue.
In case there are different doc versions, I'm referring to doc version .2 from Oct 15. |
|
#2
|
||||
|
||||
|
Re: Pointers and Tank Drive?
#include "WPILib.h"
class RobotDemo : public SimpleRobot { RobotDrive *Bot; // robot drive system Joystick *stickRight; Joystick *stickLeft; DriverStation *ds; // driver station public: RobotDemo(void) { ds = DriverStation::GetInstance(); Bot = new RobotDrive(1, 2); // create robot drive base stickRight = new Joystick(1); stickLeft = new Joystick(2); GetWatchdog().SetExpiration(100); } and the Operator: void OperatorControl(void) { while (1) { Bot.TankDrive(&stickLeft, &stickRight); } } }; START_ROBOT_CLASS(RobotDemo); I edited it, but... C:/WindRiver/workspace/ll/MyRobot.cpp:38: error: request for member `TankDrive' in `((RobotDemo*)this)->RobotDemo::Bot', which is of non-class type `RobotDrive*' Thats what it says... If its not too much to ask, whats wrong?? ![]() |
|
#3
|
||||
|
||||
|
Re: Pointers and Tank Drive?
Now that Bot is a pointer, you need to use the arrow operator to access the TankDrive method. You also need to remove the & from stickLeft and stickRight that was turning them into pointers. TankDrive expects two pointer inputs and since stickLeft and stickRight are already pointers, you can pass them in directly. Try this out:
Bot->TankDrive(stickLeft, stickRight); Last edited by Dave Scheck : 18-12-2008 at 18:48. |
|
#4
|
||||
|
||||
|
Re: Pointers and Tank Drive?
void OperatorControl(void)
{ while (1) { Bot->TankDrive(&stickLeft, &stickRight); } } }; I tried that and here are the errors that r showing up! The only line highlighted as having an error is "Bot->TankDrive(&stickLeft, &stickRight);" C:/WindRiver/workspace/ll/MyRobot.cpp: In member function `virtual void RobotDemo::OperatorControl()': C:/WindRiver/workspace/ll/MyRobot.cpp:38: error: no matching function for call to `RobotDrive::TankDrive(Joystick**, Joystick**)' C:/WindRiver/vxworks-6.3/target/h/WPILib/RobotDrive.h:43: note: candidates are: void RobotDrive::TankDrive(GenericHID*, GenericHID*) C:/WindRiver/vxworks-6.3/target/h/WPILib/RobotDrive.h:44: note: void RobotDrive::TankDrive(GenericHID*, unsigned int, GenericHID*, unsigned int) C:/WindRiver/vxworks-6.3/target/h/WPILib/RobotDrive.h:45: note: void RobotDrive::TankDrive(float, float) C:\WindRiver\vxworks-6.3\host\x86-win32\bin\make.exe: *** [SimpleTemplate_partialImage/Debug/Objects/ll/MyRobot.o] Error 1 Build Failed in Project 'll' (Process Exit Value was 2): 2008-12-18 18:47:20 (Elapsed Time: 00:02) |
|
#5
|
||||
|
||||
|
Re: Pointers and Tank Drive?
Nevermind! I just tried exactly what you said without "&" and ur worked!!! YAY!
![]() |
|
#6
|
|||
|
|||
|
Re: Pointers and Tank Drive?
Quote:
There are two ways of declaring objects: either as an instance of the object or a pointer to the object. In the case of the instance the variable represents the object, and it is created at the time of the declaration. In the case of a pointer you are only creating the space to store the address of the object, but the object remains uncreated. With pointers you have to create the object using the new operator. Look at these two snippets of code to see the difference. Code:
Joystick stick1(1); // this is an instance of a Joystick object called stick1 stick1.GetX(); // instances are dereferenced using the dot (.) operator bot->ArcadeDrive(stick1); // and can be passed to methods as a reference Joystick * stick2; // this is a pointer to an uncreated Joystick object stick2 = new Joystick(1); // this creates the instance of the Joystick object stick2->GetX(); // pointers are dereferenced with the arrow (->) bot->ArcadeDrive(stick2); // and can be passed as pointers (notice, no &) Does this help? Last edited by BradAMiller : 18-12-2008 at 19:28. Reason: improved explanation |
|
#7
|
||||
|
||||
|
Re: Pointers and Tank Drive?
Now i understand the way pointers and instances, etc work!!! Thank you so much!!! and yep! Helps loads! ![]() |
|
#8
|
|||
|
|||
|
Re: Pointers and Tank Drive?
Quote:
Sorry about that, I missed that part of the example and just fixed it (in the next update). Thanks for pointing it out. Brad |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| omni drive vs tank | |20807 61|2|_ | Technical Discussion | 49 | 17-01-2006 13:54 |
| Tank Drive help!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | Idaman323 | Programming | 3 | 18-02-2005 15:17 |
| Tank Drive | Idaman323 | Programming | 14 | 15-02-2005 09:01 |
| Swerve/crab drive and tank turning | activemx | Technical Discussion | 9 | 23-02-2004 18:26 |
| tank drive | Stormhammer | Programming | 11 | 29-01-2004 23:08 |