roboforum.ru

Технический форум по робототехнике.

Трехколесный-бермудский «керогаз» на базе Arduino

Как собрать и запрограммировать робота на Arduino(Freeduino, Roboduino, Seeduino ...). Используем Wiring и Processing.

Трехколесный-бермудский «керогаз» на базе Arduino

Сообщение EDV » 27 фев 2012, 16:01

Тут один заграничный товарищ, живущий на Бермудских островах, пытается прикрутить к своему роботу AVM Navigator.





Только вот, что-то у него не клеится всё никак, жалуется, что после включения робота, иногда серва, которая поворачивает камеру, начинает вращаться сама по себе в одну сторону.

Я сам с Arduino никогда дело не имел, так что сам ему помочь не смогу.

Он тут листинг управляющей программы прислал, которую он в Arduino прошивает.

Может кто-нибудь из форумчан сможет помочь разобраться в чёт тут дело?

Эх, очень уж хочется, что бы его трехколесный-бермудский «керогаз» уже поехал куда нужно, что бы и другие пользователи, воодушевлённые его примером, тоже бы подтягивались с установкой AVM Navigator на свои роботы.



Оригинальная тема здесь, а вот текст переписки:

bmw318be писал(а):HI EDV, thanks for the link, It is now installed in RR,

I have a new problem, everytime i plug in the USB to laptop, it keep restarting as the sparkfun also shows high delayed in pipeline, And the servo turret, keep rotating CW until the end and kept forcing the rotation even it is the extreme end, It goes to central after some time and repeated the error, As you can hear the rotation and see in the pipeline

http://youtu.be/fLv8woR4LmA

I had been finding the cause of this error but i was not able, the problems existed inconsistency, sometimes the error dissappear itself after turret errornously move for few times but this time the problem happened nonstop,
I have tried to do the following

1 upload the program to arduino
2. Shutdown the roborealm and plug in the usb to arduino
3.disactivate the turret
What happen

1. Problem still exist
2when shutdown, the error solved, when plug jn the usb to arduino and in the sparkfun assign the port, the problem exist
3. Worked but when activate again, problem exist


Other observation: when the robot is powered with the batterry on. The robot move by itself and turret keep going clockwise non stop repeatedly
EDV писал(а):You should specify some additional information regarding your Arduino controller so that we will be able to help with it:

1. What Arduino firmware version you use?
2. Which ports you use for servos connection?
3. How was implemented power supply of Arduino controller.

Please try to provide for us more detailed information for analysis.

bmw318be писал(а):1 i am using arduino 0022
2 servo turret connection pin 9 and the port that i use is port 7
3. The power of the arduino is using batterry 12 V. And since the usb is connected the power 1st is through USB.

That is why we see the pipeline has high value and once i on the power in batterry, the robot sometimes moved by itself when it is im error stage

Is it info above sufficient
EDV писал(а):The number 00022 is version of IDE that you use but we need in firmware program version number that you have uploaded/burned to Arduino controller.

If you use your own user-made arduino program then you should give us source code for analyses.

If you use already-made arduino program then you should give us link to the project where you have downloaded this firmware arduino program.
bmw318be писал(а):Here is the code, Note:L the ultrasonic sensor, I did not use it, Hope you can have a good analysis

program.robo

I think thats is the RR code, here is the arduino code:

Код: Выделить всёРазвернуть
ervo servos[12]; 
boolean pinModes[14];

unsigned int crc;
unsigned int command;
unsigned int channel;
unsigned int value;
unsigned int valueLow;
unsigned int valueHigh;
unsigned int streamDigital;
unsigned int streamAnalog;
unsigned int lastDigital;
unsigned int lastAnalog[8];

#define ARDUINO_GET_ID 0
#define ARDUINO_SET_SERVO 1
#define ARDUINO_SET_DIGITAL_STREAM 2
#define ARDUINO_SET_DIGITAL_HIGH 3
#define ARDUINO_SET_DIGITAL_LOW 4
#define ARDUINO_SET_ANALOG_STREAM 5
#define ARDUINO_DIGITAL_STREAM 6
#define ARDUINO_ANALOG_STREAM 7
#define ARDUINO_SET_ANALOG 8


void initializeAvmNav()
{
  int i;
  for (i=2;i<14;i++) pinModes[i]=-1;
  streamDigital=0;
  streamAnalog=0;
  lastDigital=-1;
  for (i=0;i<8;i++) lastAnalog[i]=-1;
}

void writePacketAvmNav()
{
  unsigned char buffer[2];   
  buffer[0]=command|128;
  buffer[1]=channel;
  Serial.write(buffer, 2);
}

void writeValuePacketAvmNav(int value)
{
  unsigned char buffer[5];   
   
  buffer[0]=command|128;
  buffer[1]=channel;
  buffer[2]=value&127;
  buffer[3]=(value>>7)&127;
  buffer[4]=(buffer[0]^buffer[1]^buffer[2]^buffer[3])&127;
   
  Serial.write(buffer, 5);
}

void readPacketAvmNav()
{
  // get header byte
  // 128 (bit 8) flag indicates a new command packet .. that
  // means the value bytes can never have 128 set!
  // next byte is the command 0-8
  // next byte is the channel 0-16

  do
  {
    while (Serial.available() <= 0) continue;
    command = Serial.read();
  }
  while ((command&128)==0);
   
  command^=128;

  while (Serial.available() <= 0) continue;
  channel = Serial.read();
}

int readValuePacketAvmNav()
{
  unsigned int valueLow;
  unsigned int valueHigh;
   
  // wait for value low byte     
  while (Serial.available() <= 0) continue;
  valueLow = Serial.read();
  if (valueLow&128) return 0;

  // wait for value high byte     
  while (Serial.available() <= 0) continue;
  valueHigh = Serial.read();
  if (valueHigh&128) return 0;
     
  // wait for crc byte     
  while (Serial.available() <= 0) continue;
  crc = Serial.read();
  if (crc&128) return 0;
   
  if (crc!=(((128|command)^channel^valueLow^valueHigh)&127)) return 0;

  value = valueLow|(valueHigh<<7);
   
  return 1;
}

/***************************************************************

Part : Ultrasound signal sensor functions for range-finder

***************************************************************/
int ultraSoundSignal = 9;

//Get the distance
float distCalc()                                                   // distance calculating function converts analog input to inches
{
  pinMode(ultraSoundSignal, OUTPUT);                                // Switch signalpin to output
  digitalWrite(ultraSoundSignal, LOW);                              // Send low pulse
  delayMicroseconds(2);                                             // Wait for 2 microseconds
  digitalWrite(ultraSoundSignal, HIGH);                             // Send high pulse
  delayMicroseconds(5);                                             // Wait for 5 microseconds
  digitalWrite(ultraSoundSignal, LOW);                              // Holdoff
  pinMode(ultraSoundSignal, INPUT);                                 // Switch signalpin to input
  digitalWrite(ultraSoundSignal, HIGH);                             // Turn on pullup resistor

  unsigned long echo = pulseIn(ultraSoundSignal, HIGH);             //Listen for echo
  //convert to CM then to inches
  return ((echo / 58.138) * 0.39 *2.2);
   
}         

/***************************************************************

Part : Main Arduino functions

***************************************************************/
void setup()
{
  //setup communication with roborealm PC
  Serial.begin(115200);
  initializeAvmNav();
  //setup for ultraSoundSignal
  //pinMode(ultraSoundSignal, OUTPUT);  // sets enable as output
}


void loop()
{
  //distCalc();                                                     
  //delay(40);
  while (Serial.available()>0)
  {
    readPacketAvmNav();
     
    switch (command)
    {
      // init
      case  ARDUINO_GET_ID:
        initializeAvmNav();
        Serial.print("ARDU");
      break;
      // servo
      case  ARDUINO_SET_SERVO:
        if ((channel>=3)&&(channel<=11))
        {
          if (readValuePacketAvmNav())
          {
            if (pinModes[channel]!=1)
            {
              servos[channel].attach(channel);
              pinModes[channel]=1;
            }
            servos[channel].writeMicroseconds(value);
            writeValuePacketAvmNav(value);
          }
        }
      break;
      //digital stream
      case  ARDUINO_SET_DIGITAL_STREAM:
        if (readValuePacketAvmNav())
        {
          streamDigital = value;
          writeValuePacketAvmNav(value);
          lastDigital=-1;
        }
      break;
      //set digital high
      case  ARDUINO_SET_DIGITAL_HIGH:
        if ((channel>=2)&&(channel<14))
        {
          if (pinModes[channel]!=2)
          {
            if (pinModes[channel]==1)
              servos[channel].detach();

            pinMode(channel, OUTPUT);
            pinModes[channel]=2;
            if (streamDigital&(1<<channel))
              streamDigital^=1<<channel;
          }
           
          digitalWrite(channel, HIGH);
          writePacketAvmNav();
        }
      break;
      //set digital low
      case  ARDUINO_SET_DIGITAL_LOW:
        if ((channel>=2)&&(channel<14))
        {
          if (pinModes[channel]!=2)
          {
            if (pinModes[channel]==1)
              servos[channel].detach();
               
            pinMode(channel, OUTPUT);
            pinModes[channel]=2;
             
            if (streamDigital&(1<<channel))
              streamDigital^=1<<channel;
          }
          digitalWrite(channel, LOW);
          writePacketAvmNav();
        }
      break;
      //analog stream
      case  ARDUINO_SET_ANALOG_STREAM:
        if (readValuePacketAvmNav())
        {
          streamAnalog = value;
          writeValuePacketAvmNav(value);
          for (channel=0;channel<8;channel++) lastAnalog[channel]=-1;
        }
      break;
      case  ARDUINO_SET_ANALOG:
        if (readValuePacketAvmNav())
        {
        if ((channel>=3)&&(channel<=11))
      {
        if (pinModes[channel]!=2)
        {
              if (pinModes[channel]==1)
                servos[channel].detach();
                 
          pinMode(channel, OUTPUT);
          pinModes[channel]=2;
            }
        analogWrite(channel, value);
        writeValuePacketAvmNav(value);
      }
        }
      break;
    }
  }
   
  for (channel=0;channel<8;channel++)
  {
    if (streamAnalog&(1<<channel))
    {
      value = analogRead(channel);
      // only send value if it has changed
      if (value!=lastAnalog[channel])
      {
        command = ARDUINO_ANALOG_STREAM;
        writeValuePacketAvmNav(value);
         
        lastAnalog[channel]=value;
      }
    }
  }

  if (streamDigital)
  {
    value=0;
    for (channel=2;channel<14;channel++)
    {
      if (streamDigital&(1<<channel))
      {
        if (pinModes[channel]!=3)
        {
          if (pinModes[channel]==1)
            servos[channel].detach();
             
          pinMode(channel, INPUT);
          pinModes[channel]=3;
          // pullup
          digitalWrite(channel, HIGH);
        }
         
        value |= digitalRead(channel)<<channel;
      }
    }

    // only send value if it has changed
    if (value!=lastDigital)
    {     
      command = ARDUINO_DIGITAL_STREAM;
      writeValuePacketAvmNav(value);

      lastDigital=value;
    }
  }
}
Аватара пользователя
EDV
 
Сообщения: 1016
Зарегистрирован: 06 июн 2007, 15:19
Откуда: Украина, Лисичанск
ФИО: Дмитрий Еремеев

Re: Трехколесный-бермудский «керогаз» на базе Arduino

Сообщение EDV » 27 фев 2012, 20:36

Ну наконец то, к обсуждению подключился Steven, теперь, надеюсь, разберёмся совместными усилиями :)
Steven Gentner писал(а):bmw318be,

The Arduino code looks fine. I would check that your power requirements are being met. Do you have external power for the Arduino or are you just using USB? Seems that something is wrong with that rather than the code which occasionally works.

The issue of the turret continuing past its extreme points is due to lack of communication with the PC and the Arduino. The Arduino gets the initial messages but looses connection to get the stop signal. Again, most likely a power issue.

If you download the latest Arduino code it has a heartbeat that will stop this runaway code after losing the connection to the PC after 2 seconds. This helps that issue but you still have the concern as to why the connection is bring dropped.

Obviously, check your connections too.

STeven.
Аватара пользователя
EDV
 
Сообщения: 1016
Зарегистрирован: 06 июн 2007, 15:19
Откуда: Украина, Лисичанск
ФИО: Дмитрий Еремеев

Re: Трехколесный-бермудский «керогаз» на базе Arduino

Сообщение Myp » 27 фев 2012, 22:29

если бы дело было у нас я подумал на китайский провод до ардуины. но там наверное фирмА и глючные китайские шнурки неизвестны обывателям.
<telepathmode>На вопросы отвечает Бригадир Телепатов!</telepathmode>
Всё уже придумано до нас!
Аватара пользователя
Myp
скрытый хозяин вселенной :)
 
Сообщения: 18018
Зарегистрирован: 18 сен 2006, 12:26
Откуда: Тверь по прозвищу Дверь
прог. языки: псевдокод =) сила в алгоритме!
ФИО: глубокоуважаемый Фёдор Анатольевич


Вернуться в Arduino и другие Xduino

Кто сейчас на конференции

Сейчас этот форум просматривают: Bing [Bot] и гости: 0

cron