Go to Post Courtesy and kindness should be the words for the weekend. - IndySam [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 20-01-2012, 00:29
cjlane1138 cjlane1138 is offline
Team 1138
FRC #1138 (Eagle Engineering)
Team Role: Leadership
 
Join Date: Jan 2011
Rookie Year: 2010
Location: Los Angeles
Posts: 88
cjlane1138 is an unknown quantity at this point
Pointers Issues

Hey everyone,

So, we are having issues with pointers. I just wanted to know if anyone else is getting the same errors. They are kernel task exceptions. When I get rid of the pointers and initialize the classes another way, it all works.

If anyone has a solution, please tell me. Otherwise, I just want to know if everyone else is having the same issue or it's just me....

Code:
#include "WPILib.h"
#include "Drive.h"

class RobotDemo : public SimpleRobot
{
	Drive *dr;

public:
	RobotDemo(void)
	{
		GetWatchdog().Kill();
		dr = new Drive();
		//AxisCamera &camera = AxisCamera::GetInstance();
		dr->myRobot->SetExpiration(0.1);
	}

	/**
	 * Drive left & right motors for 2 seconds then stop
	 */
	void Autonomous(void)
	{
		GetWatchdog().Kill();
		//dr->myRobot->SetSafetyEnabled(false);
		dr->myRobot->Drive(0.5, 0.0); 	// drive forwards half speed
		Wait(2.0); 				//    for 2 seconds
		dr->myRobot->Drive(0.0, 0.0); 	// stop robot
	}



	void OperatorControl(void)
	{
		GetWatchdog().Kill();
		//dr->myRobot->SetSafetyEnabled(true);
		while (IsOperatorControl())
		{
			printf("In Operator\n");
			dr->myRobot->TankDrive(dr->leftstick, dr->rightstick);
			Wait(0.01);
		}
	}

	void Disabled(void)
	{
		printf("Disabled\n");
	}
};

START_ROBOT_CLASS(RobotDemo);

It keeps giving me that the Drive *dr; has not been initialized correctly, where I believe I have. Anyone know any ways I can debug this?

Thanks,
-Eagle Engineering 1138

Last edited by cjlane1138 : 20-01-2012 at 11:42.
Reply With Quote
  #2   Spotlight this post!  
Unread 20-01-2012, 00:48
mikets's Avatar
mikets mikets is offline
Software Engineer
FRC #0492 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Bellevue, WA
Posts: 671
mikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of light
Re: Pointers Issues

If you suspect you have a problem with your code, you need to post it so other people can help you.
__________________
Reply With Quote
  #3   Spotlight this post!  
Unread 20-01-2012, 11:42
cjlane1138 cjlane1138 is offline
Team 1138
FRC #1138 (Eagle Engineering)
Team Role: Leadership
 
Join Date: Jan 2011
Rookie Year: 2010
Location: Los Angeles
Posts: 88
cjlane1138 is an unknown quantity at this point
Re: Pointers Issues

Quote:
Originally Posted by mikets View Post
If you suspect you have a problem with your code, you need to post it so other people can help you.
Just posted the code in the main post.
Reply With Quote
  #4   Spotlight this post!  
Unread 20-01-2012, 12:16
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,113
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: Pointers Issues

Quote:
Originally Posted by cjlane1138 View Post
Code:
		dr = new Drive();

It keeps giving me that the Drive *dr; has not been initialized correctly, where I believe I have. Anyone know any ways I can debug this?
Is there indeed a Drive() constructor with no parameters?
Reply With Quote
  #5   Spotlight this post!  
Unread 20-01-2012, 12:38
cjlane1138 cjlane1138 is offline
Team 1138
FRC #1138 (Eagle Engineering)
Team Role: Leadership
 
Join Date: Jan 2011
Rookie Year: 2010
Location: Los Angeles
Posts: 88
cjlane1138 is an unknown quantity at this point
Re: Pointers Issues

Quote:
Originally Posted by Alan Anderson View Post
Is there indeed a Drive() constructor with no parameters?
No, I have a separate Drive class.

Drive.h
Code:
#ifndef DRIVE_H_
#define DRIVE_H_
#include "WPILib.h"

class Drive
{
public:
	Drive();
	
	RobotDrive *myRobot;
	
	Jaguar *leftmotor;
	Jaguar *rightmotor;
	
	Joystick *leftstick;
	Joystick *rightstick;
};

#endif
Drive.cpp
Code:
#include "WPILib.h"
#include "Drive.h"

Drive::Drive()
{
	printf("Initializing Drive.cpp\n");
	
	leftmotor = new Jaguar(1);
	rightmotor = new Jaguar(2);
	
	myRobot = new RobotDrive(leftmotor, rightmotor);
	
	leftstick = new Joystick(1);
	rightstick = new Joystick(2);
};
There is the header file and the cpp file.
MyRobot is in the main post.
Reply With Quote
  #6   Spotlight this post!  
Unread 20-01-2012, 19:11
wireties's Avatar
wireties wireties is offline
Principal Engineer
AKA: Keith Buchanan
FRC #1296 (Full Metal Jackets)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2004
Location: Rockwall, TX
Posts: 1,170
wireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond repute
Send a message via AIM to wireties
Re: Pointers Issues

Quote:
Originally Posted by cjlane1138 View Post
Hey everyone,

So, we are having issues with pointers. I just wanted to know if anyone else is getting the same errors. They are kernel task exceptions. When I get rid of the pointers and initialize the classes another way, it all works.
Another way? What way works? Do you know which line kills it?
Reply With Quote
  #7   Spotlight this post!  
Unread 20-01-2012, 22:33
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,113
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: Pointers Issues

I seem to remember something about needing to initialize things in the same order they were defined. This is just a guess, but have you tried moving the
Code:
myRobot = new RobotDrive(leftmotor, rightmotor);
line to the very beginning of Drive:rive()?
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 03:04.

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