Simplest code to go straight


#1

I want to test if my Rangers are going straight.

Is that the right code to test them quickly?

#include <MeAuriga.h>

MeEncoderOnBoard Encoder_1(SLOT1);
MeEncoderOnBoard Encoder_2(SLOT2);

void isr_process_encoder1(void)
{
  if(digitalRead(Encoder_1.getPortB()) == 0)
  {
    Encoder_1.pulsePosMinus();
  }
  else
  {
    Encoder_1.pulsePosPlus();;
  }
}

void isr_process_encoder2(void)
{
  if(digitalRead(Encoder_2.getPortB()) == 0)
  {
    Encoder_2.pulsePosMinus();
  }
  else
  {
    Encoder_2.pulsePosPlus();
  }
}

void setup()
{
  attachInterrupt(Encoder_1.getIntNum(), isr_process_encoder1, RISING);
  attachInterrupt(Encoder_2.getIntNum(), isr_process_encoder2, RISING);
  Serial.begin(115200);
  
  //Set PWM 8KHz
  TCCR1A = _BV(WGM10);
  TCCR1B = _BV(CS11) | _BV(WGM12);

  TCCR2A = _BV(WGM21) | _BV(WGM20);
  TCCR2B = _BV(CS21);

  Encoder_1.setPulse(9);
  Encoder_2.setPulse(9);
  Encoder_1.setRatio(39.267);
  Encoder_2.setRatio(39.267);
  Encoder_1.setPosPid(1.8,0,1.2);
  Encoder_2.setPosPid(1.8,0,1.2);
  Encoder_1.setSpeedPid(0.18,0,0);
  Encoder_2.setSpeedPid(0.18,0,0);

  Encoder_1.runSpeed(200);
  Encoder_2.runSpeed(-200);
}

void loop()
{  
  Encoder_1.loop();
  Encoder_2.loop();
}

#2

Hmm, I’ll see!


#3

@el_pablo there is a document here that might help you, with some example code to try out. https://docs.google.com/document/d/1EpMWJo9pP2J_pstzXA-XHK8t00Z70SCZYwZ_Kl7VLuw/view

If your ranger is not travelling in a straight line, then look for friction in the assembly (one component rubbing on another) and ensure tensions are the same if using tracks round the wheels. Also surface can have a big impact on how the robot moves (slippery surfaces can be a challenge as can bumpy ones such as carpets/rugs)


#4

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.