Pololu Robotics & Electronics
Menu
My account Comments or questions? About Pololu Contact Ordering information Distributors

Setup Loop Skipped


#1

I’, using the A Star 32U4 LV Prime with a ComMotion Motor shield to drive two brushless motors on a sumo bot. I previously used the Pololu kit bot in a competition so I just copied my code from that an changed the subroutines so that the functions would work with the new motor shield, but when I ran the code it did all kinds of weird things (either not doing the things I wanted or it did one thing forever). It turned out that it was running the code but it was skipping the void setup(). To fix it, I just put everything in the void loop() and everything that I wanted in the loop was put in an infinite while loop, so the code looked like this:

[code]void setup(){
//nothing in here
}

void loop(){
setup stuff
while (true){
actual loop stuff
}
}[/code]

I tested this by just having it configure the motors in my fake setup (in the void loop) and then turn the motors on in the while loop, and it worked fine, so I started copying over my code. Everything looks correct to me but I get the error code:
SumoBot.ino.ino: In function ‘void loop()’:
SumoBot.ino:35: error: taking address of temporary array
SumoBot.ino.ino: In function ‘void waitForButtonAndCountDown()’:
SumoBot.ino:92: error: expected unqualified-id before ‘.’ token
taking address of temporary array

Here is the code I used. (The attachment is the same as this code. I included it so it can be more easily run by anyone else.)

[code]#include <Wire.h>
#include <ComMotion.h>
#include <Pushbutton.h>
#include <QTRSensors.h>

#define COMMOTION_ADDR 30 // ComMotion Shield I²C address with all dip switches off
#define COMMOTION_OFFS 0

const int lsense=2;
const int rsense=3;
const int echoPin=4;
const int trigPin=5;

void setup() {
//I’m broken.
}

void loop() {
// put your setup code here, to run once:

Serial.begin(9600);
pinMode(2, INPUT);
pinMode(3, INPUT);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);

digitalWrite(trigPin,LOW);

Serial.println(“Initializing button”);
Pushbutton pbutton(14); // pushbutton on pin 14

Serial.println(“Initializing line detectors”);
#define NUM_SENSORS 2
unsigned int sensor_values[NUM_SENSORS];
QTRSensorsRC sensors((unsigned char[]) {2,3}, NUM_SENSORS);
// this might need to be tuned for different lighting conditions, surfaces, etc.
#define QTR_THRESHOLD 1500 // microseconds

Serial.println(“Initializing motors”);
Wire.begin();
BasicConfig(0,19,90,255,255,255,255,0,1);
EncoderConfig(2600,800,50,10);

Serial.println(“Waiting for button”);
waitForButtonAndCountDown();
Serial.println(“Counting down…”);

while (true){
sensors.read(sensor_values);
if (sensor_values[0] < QTR_THRESHOLD){
Serial.println(“foundwhiteLEFT”);
reverse();
delay(300);
spinl();
}
else if (sensor_values[1] < QTR_THRESHOLD){
Serial.println(“foundwhiteRIGHT”);
reverse();
delay(300);
spinr();
}
//Checking for an opposing bot
long duration, cm;

 digitalWrite(trigPin, HIGH);
 delayMicroseconds(10);
 digitalWrite(trigPin, LOW);

 duration = pulseIn(echoPin, HIGH);

 // convert the time into a distance
 cm = microsecondsToCentimeters(duration);

 Serial.println("*****");
 Serial.println(sensor_values[0]);
 Serial.println(sensor_values[1]);
 Serial.println(cm);
 Serial.println("*****");

 if (cm<50){
 Serial.println("distanceforward");
  forward();
 }
else{
 Serial.println("elsespin");
  spinl();
}

}
}

void waitForButtonAndCountDown(){
Pushbutton.waitForButton()
delay(5000);
}

void forward(){
IndividualMotorControl(-255,-255,0,0);
}

void reverse(){
IndividualMotorControl(255,255,0,0);
}

void spinl(){
IndividualMotorControl(-255,255,0,0);
}

void spinr(){
IndividualMotorControl(255,-255,0,0);
}

long microsecondsToInches(long microseconds){
// According to Parallax’s datasheet for the PING))), there are
// 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
// second). This gives the distance travelled by the ping, outbound
// and return, so we divide by 2 to get the distance of the obstacle.
// See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf
return microseconds / 74 / 2;
}

long microsecondsToCentimeters(long microseconds){
// The speed of sound is 340 m/s or 29 microseconds per centimeter.
// The ping travels out and back, so to find the distance of the
// object we take half of the distance travelled.
return microseconds / 29 / 2;
}[/code]
SumoBot.ino.ino (3 KB)


#2

[quote]but it was skipping the void setup()[/quote]Not likely. What is your evidence?


#3

Hello.

I agree with Jim that skipping the setup function is unlikely, but just to be sure, you should try loading one of the A-Star 32U4 Prime examples (like BlinkLEDs) to see if the issue is caused by the board or your program.

- Amanda