DC motor position control with optical encoder

I am currently working on a Move Master II RM-501 robot arm
(more info on the thing can be found here: https://labitat.dk/wiki/MOVE_MASTER_II)

I am trying to replace the original control unit with an Arduino and want to accomplish something similar to whats seen in the link.
Unfortunately I cant seem to be able to find any "documentations" on it. Like the code, what motor drivers where used, ect.
The only thing I managed to figure out is that he uses one main Arduino to send commands via I2C to 4 other Arduinos that control each individual axis and print the position of each axis to the serial monitor.
Couldn't the same thing be accomplished by just using one Arduino Mega to controll all motors at once?

I have tried a few things and managed to get at least some stuff on one axis to work by just building a regular H-Bridge with forward, reverse and enable pins. So I can drive that axis forward/backwards and at different speeds using PWM on the enable pin.

The Issue that I am having is reading out the encoders. When I do research online I keep ending up on "rotary encoders" or encoders that only have one output wich is exactly what I can't utilize, since the robot has two outputs to also determine the direction it turns.

So far the only thing I have found that worked kinda for me was this but I have issues understanding the code: http://arturnok.000webhostapp.com/linearActuator.php

My basic Idea for driving an axis of the robot is as follows
When the Arduino powers up (or is reset) it should slowly drive the motors until they reach the limit switches to define the position when the switch is pressed as zero.
Then just wait for commands that tell it in what position to drive the axis.
When driving the motor it should slowly ramp up the speed to maximum and shortly before it reaches the final position it should ramp the speed down.
It should also display the encoder position in the serial monitor.

Has anyone got an Idea on how I could get this to work or maybe knows a few better examples?

The Issue that I am having is reading out the encoders. When I do research online I keep ending up on "rotary encoders" or encoders that only have one output wich is exactly what I can't utilize, since the robot has two outputs to also determine the direction it turns.

Have you managed to determine the pinout of the rotary encoder ?

Here is a simple program that reads the state of a rotary encoder with 2 outputs to determine which direction the encoder is turning

const byte channelA = 7;
const byte channelB = 8;

byte currentStateA = HIGH;
byte previousStateA = HIGH;
byte currentStateB = HIGH;
byte previousStateB = HIGH;

void setup()
{
  Serial.begin(115200);
  pinMode(channelA, INPUT);
  pinMode(channelB, INPUT);
}

void loop()
{
  previousStateA = currentStateA;
  currentStateA = digitalRead(channelA);
  previousStateB = currentStateB;
  currentStateB = digitalRead(channelB);
  if (currentStateA != previousStateA && currentStateA == LOW)
  {
    if (currentStateB == LOW)
    {
      Serial.println("forwards\n");
    }
  }
  if (currentStateB != previousStateB && currentStateB == LOW)
  {
    if (currentStateA == LOW)
    {
      Serial.println("reverse\n");
    }
  }
}

Thanks for the reply :slight_smile:

Yeah i have determined the pinout of the encoder:

Red: 5V
White: A
Green: B
Black: GND

CJS9000:
I am currently working on a Move Master II RM-501 robot arm
(more info on the thing can be found here: MOVE MASTER II - Labitat)

I am trying to replace the original control unit with an Arduino and want to accomplish something similar to whats seen in the link.
Unfortunately I cant seem to be able to find any "documentations" on it. Like the code, what motor drivers where used, ect.
The only thing I managed to figure out is that he uses one main Arduino to send commands via I2C to 4 other Arduinos that control each individual axis and print the position of each axis to the serial monitor.
Couldn't the same thing be accomplished by just using one Arduino Mega to controll all motors at once?

I have tried a few things and managed to get at least some stuff on one axis to work by just building a regular H-Bridge with forward, reverse and enable pins. So I can drive that axis forward/backwards and at different speeds using PWM on the enable pin.

The Issue that I am having is reading out the encoders. When I do research online I keep ending up on "rotary encoders" or encoders that only have one output wich is exactly what I can't utilize, since the robot has two outputs to also determine the direction it turns.

So far the only thing I have found that worked kinda for me was this but I have issues understanding the code: http://arturnok.000webhostapp.com/linearActuator.php

My basic Idea for driving an axis of the robot is as follows
When the Arduino powers up (or is reset) it should slowly drive the motors until they reach the limit switches to define the position when the switch is pressed as zero.
Then just wait for commands that tell it in what position to drive the axis.
When driving the motor it should slowly ramp up the speed to maximum and shortly before it reaches the final position it should ramp the speed down.
It should also display the encoder position in the serial monitor.

Has anyone got an Idea on how I could get this to work or maybe knows a few better examples?

This is where a PID loop would be used - the error in position is used to drive the loop, the loop output drives the motor. A PID with integral-windup-prevention is needed for large step-changes, note.