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:


class RobotDemo : public SimpleRobot
{
        RobotDrive myRobot; // robot drive system
	Joystick stick1, stick2; // only joystick
	ADXL345_SPI adxl;


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!

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?

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:


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?

Apologies! We just edited our code to try and find values:


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?

I thought %d was for integers. Doesn’t the GetAcceleration() method return a float?

in ADXL345_SPI.h, it says

 virtual double GetAcceleration(Axes axis); 

%d is for doubles
%f is for floats
%i is for integers

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