Test motor dc encoder 25GA370


Test using arduino mega 2560 and adafruit v1 motor shield this is my code

#include <AFMotor.h>

AF_DCMotor motor(1);
AF_DCMotor motor2(3);
volatile long int encoder_pos = 0;
volatile long int encoder_pos2 = 0;
//The sample code for driving one way motor encoder
const byte encoder0pinA = 18;//A pin -> the interrupt pin 0
const byte encoder0pinB = 31;//B pin -> the digital pin 3


const byte encoder1pinA = 19;//A pin -> the interrupt pin 0
const byte encoder1pinB = 33;//B pin -> the digital pin 3


byte encoder0PinALast;
byte encoder1PinALast;
int duration;//the number of the pulses
boolean Direction;//the rotation direction


void setup()
{
  Serial.begin(115200);//Initialize the serial port
//  EncoderInit();//Initialize the module

  attachInterrupt(digitalPinToInterrupt(encoder0pinA), encoder, RISING);

  attachInterrupt(digitalPinToInterrupt(encoder1pinA), encoder2, RISING);

}

void encoder(){

  if(digitalRead(encoder0pinB) == HIGH){
    encoder_pos++;
  }else{
    encoder_pos--;
  }
}

void encoder2(){

  if(digitalRead(encoder1pinB) == HIGH){
    encoder_pos2++;
  }else{
    encoder_pos2--;
  }
}

void loop()
{
//  motor.run(BACKWARD);
//  motor.setSpeed(40);
////  delay(200);
//
////  motor.run(BACKWARD);
////  motor.setSpeed(150);
////  delay(200);
//
//  motor2.run(FORWARD);
//  motor2.setSpeed(50);
//  delay(200);

//  motor2.run(FORWARD);
//  motor2.setSpeed(150);
//  delay(200);
  
  
  Serial.print("Pulse:");
  Serial.println(duration);
  Serial.print("Encoder pos1:");
  Serial.println(encoder_pos);
  Serial.print("Encoder pos2:");
   Serial.println(encoder_pos2);
  duration = 0;
  delay(1000);

  
  
}

void EncoderInit()
{
  Direction = true;//default -> Forward
  pinMode(encoder0pinB,INPUT);
  attachInterrupt(0, wheelSpeed, CHANGE);
}

void wheelSpeed()
{
  int Lstate = digitalRead(encoder0pinA);
  if((encoder0PinALast == LOW) && Lstate==HIGH)
  {
    int val = digitalRead(encoder0pinB);
    if(val == LOW && Direction)
    {
      Direction = false; //Reverse
    }
    else if(val == HIGH && !Direction)
    {
      Direction = true;  //Forward
    }
  }
  encoder0PinALast = Lstate;

  if(!Direction)  duration++;
  else  duration--;
}
Advertisement

Install cmake from source


Notes howto install cmake from source

Some ros package can’t install because minimum cmake, this is how i do it

#download cmake version here https://cmake.org/files/

wget https://cmake.org/files/v3.8/cmake-3.8.0.tar.gz

#and uncompress package using 

tar xvf  cmake-3.8.0.tar.gz

sudo apt-get install build-essential

sudo ./bootstrap

sudo make 

sudo make install

Alternate remote desktop


I find new tools for remote desktop it is really easy to setup, very usefull for alternatif remote desktop like other vnc, the name of application is nomachine its fast and the instalation really easy

I’m using this app for remote my ros robot, and that’s it

Happy coding and salam ngoprek

Resize jetson nano vnc display


Add this at  /etc/X11/xorg.conf 
Section "Screen"
   Identifier    "Default Screen"
   Monitor       "Configured Monitor"
   Device        "Tegra0"
   SubSection "Display"
       Depth    24
       Virtual 1280 800 # Modify the resolution by editing these values
   EndSubSection
EndSection

I make robot


Siapa yang tidak suka dengan robot, dan project membuat robot ini benar benar menyenangkan :), dan anak2 saya pun suka dengan robot

Dan sudah sejak lama saya ingin punya robot, dan ini ada beberapa dokumentasi saya membuat robot 🙂

ceritanya mau membuat EOD robot
Simple robot kesukaan anak anak dari tempat sampah 🙂
Dancing Bot

Dan untuk melanjutkan project tentang robot ini kali ini saya coba buat versi yang lebih advance, menggunakan Lidar, dan menggunakan ROS (Robot Operating System)

Idenya adalah memanfaatkan cooler yang sudah rusak ini menjadi robot security seperti di axiom di film Wall E kira kira begini penampakannya

Continue reading “I make robot”
%d bloggers like this: