SOLVED: Navigation (gyro and accelerometer) not working?

The more technical aspects of Spirit, and carry-over discussion from Kickstarter updates.
gpvillamil
Posts: 75
Joined: Fri Jan 26, 2018 5:03 pm

SOLVED: Navigation (gyro and accelerometer) not working?

Postby gpvillamil » Mon Feb 12, 2018 1:38 am

Apparently you need to call the NavigationXY() or SimpleNavigation() functions to update the accelerometer and gyro functions.

==============================================

I'm trying the accelerometer and gyro functions in the Navigation tab, and it seems to not be working.

While running the sketch I moved Spirit in all axes. An equivalent sketch on an Arduino with an accelerometer generated very clear changes in values.

I've included the NavigationBegin() function as specified in the Ringo documentation. Not sure what is wrong here.

Here's the output:

Code: Select all

Heading: 0 Acc X: 0 Acc Y: 0 Acc Z: 0
Heading: 0 Acc X: 0 Acc Y: 0 Acc Z: 0
Heading: 0 Acc X: 0 Acc Y: 0 Acc Z: 0
...


and here is the sketch:

Code: Select all


/*

Spirit Rover Robot
Spirit_BaseSketch_Rev01
Version 1.1 10/2017

Significant portions of this code written by
Dustin Soodak for Plum Geek LLC. Some portions
contributed by Kevin King.
Portions from other open source projects where noted.
This code is licensed under:
Creative Commons Attribution-ShareAlike 2.0 Generic (CC BY-SA 2.0)
https://creativecommons.org/licenses/by-sa/2.0/
Visit http://www.plumgeek.com for PiSpirit information.
Visit http://www.arduino.cc to learn about the Arduino.

*/

#include "Hardware.h"

void setup(){

  // ************ THE SETUP ITEMS BELOW SHOULD GENERALLY BE USED FOR ALL SPIRIT SKETCHES **************
 
  hardwareBegin();                    //initialize Spirit's Arduino processor to work with his circuitry
  SPI_Reset();                        //resets and turns on the SPI port
  playStartChirp();                   //Play startup chirp and blink eyes
  servoCenters();                     //Place all servos back in default position
 
  // ************ THE SETUP ITEMS BELOW CAN BE CUSTOMIZED FOR YOUR SPECIFIC SPIRIT SKETCH **************


  // add your own setup code here

NavigationBegin();

    Serial.begin(57600);   
}


void loop(){

  // add your own loop code here
 
  Serial.print("Heading: ");
  Serial.print(GetDegrees());
  // Serial.print(PresentHeading());
  // Serial.print(GyroRawToDegrees(GyroPosition[0]));
  Serial.print(" Acc X: ");
  Serial.print(GetAccelerationX());
  Serial.print(" Acc Y: ");
  Serial.print(GetAccelerationY()); 
  Serial.print(" Acc Z: ");
  Serial.println(GetAccelerationZ());
  delay(1000);

} // end of loop() function


gpvillamil
Posts: 75
Joined: Fri Jan 26, 2018 5:03 pm

Re: SOLVED: Navigation (gyro and accelerometer) not working?

Postby gpvillamil » Fri Feb 16, 2018 4:45 am

This code does seem to work now.

It returns heading + acceleration in X, Y, Z and then rotates the rover back & forth 90 degrees. It's not super accurate, but is not bad. The MoveWithOptions() function seems to use the gyro, so calling that function with the current heading as the intended heading will keep the rover moving in a straight line.

Code: Select all

#include "Hardware.h"

void setup(){

  // ************ THE SETUP ITEMS BELOW SHOULD GENERALLY BE USED FOR ALL SPIRIT SKETCHES **************
 
  hardwareBegin();                    //initialize Spirit's Arduino processor to work with his circuitry
  SPI_Reset();                        //resets and turns on the SPI port
  playStartChirp();                   //Play startup chirp and blink eyes
  servoCenters();                     //Place all servos back in default position
 
  // ************ THE SETUP ITEMS BELOW CAN BE CUSTOMIZED FOR YOUR SPECIFIC SPIRIT SKETCH **************


  // add your own setup code here

NavigationBegin();
Serial.begin(57600);   
}


void loop(){

  // add your own loop code here

  NavigationXY(70,200); // apparently need to call this periodically
 
  Serial.print("Heading: ");
  Serial.print(GetDegrees());
  // Serial.print(PresentHeading());
  // Serial.print(GyroRawToDegrees(GyroPosition[0]));
  Serial.print(" Acc X: ");
  Serial.print(GetAccelerationX());
  Serial.print(" Acc Y: ");
  Serial.print(GetAccelerationY()); 
  Serial.print(" Acc Z: ");
  Serial.println(GetAccelerationZ());

  RotateAccurate(90,2000);

RotateAccurate(-90,2000);

} // end of loop() function

Kevin
Posts: 176
Joined: Tue Jul 28, 2015 12:56 am

Re: SOLVED: Navigation (gyro and accelerometer) not working?

Postby Kevin » Fri Feb 16, 2018 4:42 pm

Thanks for posting that gp. I appreciate your help on this! :)

headamage
Posts: 29
Joined: Mon Dec 04, 2017 5:27 pm

Re: SOLVED: Navigation (gyro and accelerometer) not working?

Postby headamage » Sun Mar 18, 2018 6:15 pm

Kevin wrote:Thanks for posting that gp. I appreciate your help on this! :)

is this currently exposed to raspberry pi and supported in the python scripts?
I would love to add this to my cloud robotics code.


Who is online

Users browsing this forum: No registered users and 2 guests