Show Posts
Pages: [1] 2 3 4
1  Topics / Robotics / Re: Autonomous Arduino Car on: May 29, 2013, 10:16:46 am
Hi All,

I am using a 1/24 the scale tank chassis to work out object avoidance for my hexapod.   Control setups are pretty simple for front and rear avoidance,  speed is an issue as you you have to consider how far you travel between checks.

It gets way more interesting as you try to add in object avoidance.

My test environment is a box the tank sits on, the tracks do not touch the ground and I can get rough settings dialed in.   I have an r/c receiver attached to allow me to kill the motors as required.  I can post code but really I started with the samples for the ultrasonic and my sabretooth motor control and went from there.  Currently only the stop process has been implemented as my side sensors have just arrived.
2  Using Arduino / Programming Questions / Re: 3 RC Channels, and 3 Servos on: April 05, 2013, 04:05:59 pm
Have you tried connecting all the servos to non pwm pins ?

I will setup my servo test up later and get you the code that works for me.

No Mixing but all the servo's worked.  I use a mega 2560 spectrum receiver and dx 7 TX  Servos were whatever I had handy
3  Using Arduino / Programming Questions / Re: 3 RC Channels, and 3 Servos on: April 05, 2013, 10:18:42 am
Well I manage all 6 on a standard Spectrum receiver as long as you have the pins you should be good.

Try with one servo do you still have jitter ?

If not add the next one in, make sure you don't have a flaky servo.

Next how do you have everything connected ?  Picture or diagram would help.
4  Using Arduino / Programming Questions / Re: I2C - Analog on: April 04, 2013, 12:19:40 pm
If the IC2 scanner finds no devices, then either the power is no good ie the gryo is not powered or your connections are incorrect.

Does the IC2 scanner find any devices ?
5  Using Arduino / Programming Questions / Re: 3 RC Channels, and 3 Servos on: April 04, 2013, 12:16:37 pm
Erni is correct your servos are not rated for 9 volts they will work but failure, jitter and strange behavior will occur.  The R/C device has a circuit that reduces the voltage.  You will also want to check your receiver they are normally 5 volts as well.  You need to get an R/C BEC that will reduce the voltage to 5 volts, battery to BEC to servos and receiver.
6  Topics / Robotics / Re: SOLVED: Devantech SD21 servo contr. and desperate programmer, after one year... on: April 04, 2013, 10:42:10 am
You are going to pretty much figure it out on your own.   My code is in limbo for a few more weeks, then I will be back to it.  But this is not a popular platform for multileg robots.

There is tons of stuff out there, but start simple 1 leg, your controller and some basic code.  Make that leg work then get the leg on the other side to work, it does not have to look really pretty it just has function.   Remember to define ranges of motion.

I have about 15 sketches related to this, in addition to the main, just to test out ideas and control schemes.

You are best off to work through the code yourself multileg robots are fairly complex you need to understand what each section your code is doing.  You can not "fake" your way through it.

I am happy to help you out figuring out the board, but for clarity you start your own post.
7  Using Arduino / Programming Questions / Re: I2C - Analog on: April 04, 2013, 10:23:24 am
Are you sure the device address is correct ?  There is an alternate IC2 Lib you can use http://dsscircuits.com/articles/arduino-i2c-master-library.html

This one a a bus scan function built in.  It might help.
8  Using Arduino / Programming Questions / Re: Dumb Question - Global variable not holding value on change on: March 29, 2013, 01:04:00 pm
Just wanted to say thanks to all and particularly Nick, the recursive call, and another bad section of code were generating the problem.  I removed that call as well as another similar piece of code and works as expected.  The card reading code needs some clean up to read the card correctly but that is pretty minor.

Thanks again for your help.
9  Using Arduino / Programming Questions / Re: Dumb Question - Global variable not holding value on change on: March 28, 2013, 09:55:45 pm
Thanks for your reply Nick,

I used the RFID reader code as I found it, with very little change. 

I will clean it up in the am and get rid of the recursive call.
 
I generally try to clean up my code once it is working, but had done so yet with this, I had not considered the impact of the recursive call.
10  Using Arduino / Programming Questions / Re: Dumb Question - Global variable not holding value on change on: March 28, 2013, 06:37:23 pm
Yes I am aware that the variable is inside the loop function now, it is however outside the nested while statements.  So once the loop is restarted it will, be reset to zero that is fine.

I made that change when I realized that the data is getting corrupted.  However it changes nothing significant in the behavior of the code, please see the output from the serial monitor attached to the full code post.

Inside the if statement the variable is set to 6 immediately upon exit is corrupted.
11  Using Arduino / Programming Questions / Re: Dumb Question - Global variable not holding value on change on: March 28, 2013, 04:33:16 pm
Everything as requested, this code compile and runs the problem as noted above is in the armed 2 if statement.

Output from serial :

the garbage characters are from the print right after the arm 2 check.

Code:
#include <I2C.h>

// FOR RFID Reader

#include <SoftwareSerial.h>
#define RFID_READ 0x01
#define txPin 6
#define rxPin 10

// define Devantech LCD address

#define DLCD 0x63

int int_sys = 1;
int y = 0;
int z = 0;
int err_c = 0;
int i;

int second=00;
int minut;
int hour=0; // declare time variables
int armed = 0;

int go_boom = 0;
int big_boom = 0;
int Arm_card[4];
int Test_val[4] = {1,248,124,0};

// canned messages

char message[10] = "Hello Hal";
char message2[15] ="Arm the System";
char message3[15] ="Verfiying Code";
char boom[2] ="b";
char message4[14] ="Arming Failed";

// For data from RFID tags

SoftwareSerial mySerial(rxPin, txPin);

int val;
int runs = 0;
char Set1[5];
char Set2[5];
char Set3[5];
char Set4[5];
char sec[3];
char minu[3];
char hou[3];
char zer[2] = "0";

void setup()
{
  I2c.begin();
  Serial.begin(9600);
  mySerial.begin(9600);
  pinMode(txPin, OUTPUT);    
  pinMode(rxPin, INPUT);
  minut = 5;  
}

void loop()
{
  int eXtime = 0;  
  while (big_boom == 0)
    {
     while (int_sys == 1)
       {
        clr_scr();
        backlight_on();
        LCD_Message(message,10,1);
        LCD_Message(message2,15,2);
        delay(3000); //make em wait
        // debug only
        // I2c.scan();
        int_sys = 2;
       }

       Get_card();
       check_arm();

       if (armed ==2)
         {
          clr_scr();
          LCD_Message(message4,14,1);
          eXtime = eXtime + 6;
          Serial.print(eXtime);
          Serial.println(" in loop xtime val");
          delay (5000);
          }
        Serial.print(eXtime);
        Serial.println(" after armed 2 if xtime val");
       if (armed==1)
         {
           clr_scr();
           minut=minut + eXtime;
           Serial.print(eXtime);
           Serial.println(" xtime val");
           Serial.print(minut);
           Serial.println(" minut val");
           itoa(minut,minu,10);
           LCD_Message(minu,3,1);
           itoa(second,sec,10);
           LCD_Message(sec,3,1);

           while (go_boom==0)
             {
              countdown();
              if (minut == 0)
                {
                 if (second == 0)
                   {
                    go_boom = 1;
                    clr_scr();
                    LCD_Message(boom,16,1);
                    delay(2000);
                    big_boom = 1;
                   }    
                 }    
               }  
         }  
     }
 }

// LCD functions
// All tested and working as expected

 void backlight_on()
{
  err_c = I2c.write(DLCD,0);  // set the register pointer
  if (err_c != 0)
    {
     Serial.print(err_c);
     Serial.println("  Error setting pointer");
    }  

  err_c = I2c.write(DLCD,0,19);
  if (err_c != 0)
    {
      Serial.print(err_c);
      Serial.println("  Error setting backlight on");
    }  
}

void backlight_off()
{
   err_c = I2c.write(DLCD,0);  // set the register pointer
  if (err_c != 0)
    {
      Serial.print(err_c);
      Serial.println("  Error setting pointer");
    }
 err_c = I2c.write(DLCD,0,20);
  if (err_c != 0)
    {
      Serial.print(err_c);
      Serial.println("  Error setting backlight off");
    }  
  
}  

void LCD_Message(char mess[],int C_len, int M_line)
{
  if (M_line == 2)
   {
    Line_2();
   }
  err_c = I2c.write(DLCD,0);  // set the register pointer
  if (err_c != 0)
    {
      Serial.print(err_c);
      Serial.println("  Error setting pointer");
    }
for (i=0;i<C_len;i++)
 {
 err_c = I2c.write(DLCD,0,mess[i]);
  if (err_c != 0)
    {
      Serial.print(err_c);
      Serial.println("  Error writing message");
    }
 }
}
  
void Line_2()
{
  err_c = I2c.write(DLCD,0);  // set the register pointer
  if (err_c != 0)
    {
      Serial.print(err_c);
      Serial.println("  Error setting pointer");
    }

  err_c = I2c.write(DLCD,0,13);
  if (err_c != 0)
    {
      Serial.print(err_c);
      Serial.println("  Error writing message 2");
    }
}

void clr_scr()
{
   err_c = I2c.write(DLCD,0);  // set the register pointer
  if (err_c != 0)
    {
      Serial.print(err_c);
      Serial.println("  Error setting pointer");
    }
  err_c = I2c.write(DLCD,0,12);
  if (err_c != 0)
    {
      Serial.print(err_c);
      Serial.println("  Error clearing screen");
    }    
}

void check_arm ()
{
  int arm_good = 0;
  for(i=0;i<4;i++)
   {
    if (Arm_card[i+1] == Test_val[i])
      {
       arm_good = arm_good + 1;          
      }
   }
   if (arm_good == 4)
    {
     armed = 1;
    }  
   else
    {
     armed = 2;
    }  
}  

// RFID read section note for new cards

void Get_card ()
{
  int val;
  int got_data = 0;
  while (got_data == 0)
  {
    mySerial.write("!RW");
    mySerial.write(byte(RFID_READ));
    mySerial.write(byte(32));
    mySerial.available();
 
    if(mySerial.available() > 0)
    {      
      val = mySerial.read();                        //The mySerial.read() procedure is called, but the result is not printed because I don't want the "error message: 1" cluttering up the serial monitor
      if (val != 1)                                   //If the error code is anything other than 1, then the RFID tag was not read correctly and any data collected is meaningless. In this case since we don't care about the resultant values they can be suppressed
       {suppressAll();}                              
   }      
 
   if(mySerial.available() > 0)
   {      
    clr_scr();
    LCD_Message(message3,15,1);
    delay(2000); // more waiting :)
    val = mySerial.read();
    itoa(val,Set1,10);
    LCD_Message(Set1,4,2);
    delay(2000);
    Arm_card[1] = val;
    Serial.print("1st:");
    Serial.println(val);
    }

   if(mySerial.available() > 0) {        
    val = mySerial.read();
    itoa(val,Set2,10);
    LCD_Message(Set2,4,1);
    delay(2000);
    Arm_card[2] = val;
    Serial.print("2nd:");
    Serial.println(val);
    }

   if(mySerial.available() > 0) {      
    val = mySerial.read();
    itoa(val,Set3,10);
    LCD_Message(Set3,4,1);
    delay(2000);
    Arm_card[3] = val;    
    Serial.print("3rd:");
    Serial.println(val);
    }

   if(mySerial.available() > 0) {          
    val = mySerial.read();
    itoa(val,Set4,10);
    LCD_Message(Set4,4,1);
    delay(2000);
    Arm_card[4] = val;
    Serial.print("4th:");
    Serial.println(val);
    Serial.println("-----------------");
    got_data = 1;
   }  
   delay(750);
  }
}

void suppressAll()                                //suppresses the "null result" from being printed if no RFID tag is present
{
    if(mySerial.available() > 0)
    { mySerial.read();
      suppressAll();
    }
}


/***********************************************************
* Main countdown timer                                     *
*                 countdown()                              *
************************************************************/
void countdown()
{

  static unsigned long lastTick = 0; // set up a local variable to hold the last time we decremented one second
// (static variables are initialized once and keep their values between function calls)
 
// decrement one second every 1000 milliseconds
  if (second > 0) {
      if (millis() - lastTick >= 1000) {
          lastTick = millis();
          second--;
          clr_scr();
          itoa(minut,minu,10);
          LCD_Message(minu,3,1);
          itoa(second,sec,10);
          if (second < 10)
           {
           LCD_Message(zer,1,1);
           }  
          LCD_Message(sec,3,1);

      }
  }
 
 // decrement one minute every 60 seconds
  if (minut > 0) {
      if (second <= 0) {
          minut--;
          second = 60; // reset seconds to 60
      }
  }
 
// decrement one hour every 60 minutes
  if (hour > 0) {
      if (minut <= 0) {
          hour--;
          minut = 60; // reset minutes to 60
      }//closes if
  }//closes if
 
}
12  Using Arduino / Programming Questions / Re: Dumb Question - Global variable not holding value on change on: March 28, 2013, 04:05:26 pm
ukHelibob,

That is why I am confused, your explanation is exactly my understanding of how things should be working, but they are not.  I was hoping I had simply done something unusually dumb and missed it.   I will post or attach the whole section of code later.
13  Using Arduino / Programming Questions / Re: Dumb Question - Global variable not holding value on change on: March 28, 2013, 03:43:42 pm
that is ok I found that I am getting corruption in that value, if i try to print after the if  it prints 5 and a garbage character,the second print statement does not print at all. so I have a bigger issue, I need to review my variable declarations may be I have too many for an UNO.
14  Using Arduino / Programming Questions / Re: Dumb Question - Global variable not holding value on change on: March 28, 2013, 03:16:05 pm
Nope the declared as int eXtime no initial value set.

Yes arm is set to 2 when an incorrect card is swiped, I removed print statements from there as the value was being set correctly with in the if, it is not staying set however.

If I print the the value, at the point I add 5 on the 1st bad card eXtime is equal to 5
If i print the value of eXtime as soon as the if ends it prints as zero.

everything else works as expected

I can include all the code but it is fairly large.
15  Using Arduino / Programming Questions / Dumb Question - Global variable not holding value on change on: March 28, 2013, 02:48:34 pm
I am trying to increase a value by 5 the value is an integer,  the intent is to increment the value if an invalid RFID card is read.
Card reading LCD display works fine, I have done or am not doing something right but I just can not see it.

Code Section that is failing

Notes:
eXtime is declared Global
It is only used in this area -searched the code to make sure
Serial output shows the value as zero everywhere but inside the if when is incremented.
This is not correct function as I understand it a global variable should maintain it's value until the loop restarts

portion that is failing
Code:

while (big_boom == 0)
 {
  while (int_sys == 1)
  {
  clr_scr();
  backlight_on();
  LCD_Message(message,10,1);
  LCD_Message(message2,15,2);
  delay(3000); //make em wait
  // debug only
  // I2c.scan();
  int_sys = 2;
  }

 Get_card();
 check_arm();
 Serial.print(eXtime);
 Serial.println(" eXtime val");
 if (armed ==2)
  {
   clr_scr();
   LCD_Message(message4,14,1);
   eXtime = eXtime + 5;
   delay (10000);
  }
 if (armed==1)
  {
   clr_scr();
   minut=minut + eXtime;
     Serial.print(eXtime);
      Serial.println(" xtime val");
      Serial.print(minut);
      Serial.println(" minut val");
   itoa(minut,minu,10);
   LCD_Message(minu,3,1);
   itoa(second,sec,10);
   LCD_Message(sec,3,1);



Pages: [1] 2 3 4