Go to Post You can build bridges, or you can burn them. The choice is yours. - dlavery [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 12-02-2013, 18:41
progal's Avatar
progal progal is offline
Programmer
AKA: Shelby
FRC #0384 (Sparky)
Team Role: Programmer
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Glen Allen
Posts: 15
progal is an unknown quantity at this point
Accelerometer Code Making Robot Stop Moving

Hey, apologies if this is an already answered question. I couldn't find anything on the topic.
The problem that we're having is whenever we state the accelerometer (not even doing anything with it, but just instantiating it), our robot components stop working completely. The robot won't move, et cetera.

Also, we don't know how to get the values from the gyro once in teleop, or rather the method to use to get the values from the accelerometer.

This is our code:
Code:
class RobotDemo : public SimpleRobot
{
        RobotDrive myRobot; // robot drive system
	Joystick stick1, stick2; // only joystick
	ADXL345_SPI adxl;
Code:
public:
	RobotDemo(void):
		myRobot(2, 1),	// these must be initialized in the same order
		stick1(1),		// as they are declared above.
		stick2(2),
		adxl(5, 6, 7, 8, ADXL345_SPI::kRange_2G)
Thanks in advance!
__________________

C++ Programmer
Reply With Quote
  #2   Spotlight this post!  
Unread 13-02-2013, 06:58
kenfox kenfox is offline
Registered User
FRC #3322 (Eagle Imperium)
Team Role: Mentor
 
Join Date: Jan 2013
Rookie Year: 2013
Location: Ann Arbor, MI
Posts: 51
kenfox is a glorious beacon of lightkenfox is a glorious beacon of lightkenfox is a glorious beacon of lightkenfox is a glorious beacon of lightkenfox is a glorious beacon of light
Re: Accelerometer Code Making Robot Stop Moving

Quote:
Originally Posted by progal View Post
whenever we [instantiate] the accelerometer ... our robot components stop working completely.

Code:
adxl(5, 6, 7, 8, ADXL345_SPI::kRange_2G)
The constructor for ADXL345_SPI takes the digital IO module as the first parameter and has a default kRange_2G value for the 6th parameter. You are asking it to use a non-existant module #5 which probably causes the robot code to crash. Do you see an error message about using a module out of range?

If you only have one digital IO module in the cRIO, it will be module #1.

Does the following code work better?

Code:
adxl(1, 5, 6, 7, 8)
Reply With Quote
  #3   Spotlight this post!  
Unread 15-02-2013, 18:22
progal's Avatar
progal progal is offline
Programmer
AKA: Shelby
FRC #0384 (Sparky)
Team Role: Programmer
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Glen Allen
Posts: 15
progal is an unknown quantity at this point
Re: Accelerometer Code Making Robot Stop Moving

Quote:
Originally Posted by kenfox View Post
Does the following code work better?

Code:
adxl(1, 5, 6, 7, 8)
It did work.. kinda. It gave us the values but after it showed us these values it didn't update after that:
X: 0
Y: 2
Z: 4

This is how we're getting the values:
Code:
dsLCD->PrintfLine(DriverStationLCD::kUser_Line4, "Accelerometer X: %d", adxl.kAxis_X);
dsLCD->PrintfLine(DriverStationLCD::kUser_Line5, "Accelerometer Y: %d", adxl.kAxis_Y);
dsLCD->PrintfLine(DriverStationLCD::kUser_Line6, "Accelerometer Z: %d", adxl.kAxis_Z);
Is this how we should be finding the values?
__________________

C++ Programmer
Reply With Quote
  #4   Spotlight this post!  
Unread 15-02-2013, 20:13
progal's Avatar
progal progal is offline
Programmer
AKA: Shelby
FRC #0384 (Sparky)
Team Role: Programmer
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Glen Allen
Posts: 15
progal is an unknown quantity at this point
Re: Accelerometer Code Making Robot Stop Moving

Apologies! We just edited our code to try and find values:
Code:
dsLCD->PrintfLine(DriverStationLCD::kUser_Line4, "X: %d", adxl.GetAcceleration(adxl.kAxis_X));
dsLCD->PrintfLine(DriverStationLCD::kUser_Line5, "Y: %d", adxl.GetAcceleration(adxl.kAxis_Y));
dsLCD->PrintfLine(DriverStationLCD::kUser_Line6, "Z: %d", adxl.GetAcceleration(adxl.kAxis_Z));
This gave us these values:
X: 21360244
Y: 21360244
Z: 21360244

And the values never changed. Is there a "reset" for the accelerometer? Any ideas?
__________________

C++ Programmer
Reply With Quote
  #5   Spotlight this post!  
Unread 16-02-2013, 00:58
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: Accelerometer Code Making Robot Stop Moving

I thought %d was for integers. Doesn't the GetAcceleration() method return a float?
Reply With Quote
  #6   Spotlight this post!  
Unread 16-02-2013, 10:27
SushenaJammi SushenaJammi is offline
Registered User
FRC #0384
 
Join Date: Feb 2013
Location: Richmond, VA
Posts: 1
SushenaJammi is an unknown quantity at this point
Re: Accelerometer Code Making Robot Stop Moving

in ADXL345_SPI.h, it says

Code:
 virtual double GetAcceleration(Axes axis);
Reply With Quote
  #7   Spotlight this post!  
Unread 16-02-2013, 10:40
progal's Avatar
progal progal is offline
Programmer
AKA: Shelby
FRC #0384 (Sparky)
Team Role: Programmer
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Glen Allen
Posts: 15
progal is an unknown quantity at this point
Re: Accelerometer Code Making Robot Stop Moving

Quote:
Originally Posted by Alan Anderson View Post
I thought %d was for integers. Doesn't the GetAcceleration() method return a float?
%d is for doubles
%f is for floats
%i is for integers

but the accelerometer values return a double as Sushena pointed out.
__________________

C++ Programmer
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 13:03.

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