About 180 Optical Encoder Motor (for mBot Ranger)

1280X1280__80_.PNG

Overview

The 180 optical encoder motor is equipped with an optical encoder that enables high-accuracy control. With two M4 threaded holes on each of the three sides, it can be easily connected to Makeblock mechanical parts and thus can be used flexibly in combination with various other parts. The customized material it uses reduces noise and promises large output torque. It supports multiple motor drivers and main control boards, such as Orion, MegaPi, MegaPi Pro, and Me Auriga.

 

Specifications

  • Reduction gear ratio: 39.6
  • Rated voltage: 7.4 V
  • No-load current: 240 mA
  • Load current: ≤750 mA
  • No-load speed: 350 ± 5% (RPM)
  • Original speed: 14,000 ± 5% (RPM)
  • Start torque: 5 kg·cm
  • Rated torque: 800 g·cm
  • Length of output shaft: 9 mm
  • Power: 3.7 W
  • Encoder rotation angle: 360°

 

Programming guide

● Program with mBlock 5
Block description (main control board: Auriga)
Block Features
output__2_.png Select a port
Set the power to -100–100
output__3_.png Select a port
Set the speed (the maximum speed depends on the motor model)
output__4_.png Select a port
Set the rotation angle (a natural number)
Set the speed (the maximum speed depends on the motor model)
output__5_.png Obtain the speed of the motor
output__6_.png Obtain the angle of the motor from the origin
After the following program runs, encoder motor 1 and encoder motor 2 rotate at the speed of 100 RPM for 1 second and stop rotating for 1 second, and then repeat this process.

1280X1280__81_.PNG

● Program with mBlock 3
Block description
Block Features
output__7_.png Select a slot
Set the power to -255–255
output__8_.png Select a slot
Set the speed (the maximum speed depends on the motor model)
output__9_.png Select a slot
Set the rotation angle (a natural number)
Set the speed (the maximum speed depends on the motor model)
output__11_.png Obtain the speed of the motor
output__12_.png Obtain the position or degree of the motor from the origin
After the following program runs, encoder motor 1 and encoder motor 2 rotate at the speed of 100 RPM for 1 second and stop rotating for 1 second, and then repeat this process.
1280X1280__82_.PNG
● Program in Arduino
If you program in Arduino, you need to use Makeblock-Library-master to control the motor.
After the following program runs, encoder motor 1 and encoder motor 2 rotate at the speed of 100 RPM for 1 second and stop rotating for 1 second, and then repeat this process.
// generated by mBlock5 for mBot Ranger
// codes make you happy

#include <Arduino.h>
#include <Wire.h>
#include <SoftwareSerial.h>
#include <MeAuriga.h>

MeEncoderOnBoard Encoder_1(SLOT1);
MeEncoderOnBoard Encoder_2(SLOT2);
MeLightSensor lightsensor_12(12);

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 move(int direction, int speed)
{
int leftSpeed = 0;
int rightSpeed = 0;
if(direction == 1){
leftSpeed = -speed;
rightSpeed = speed;
}else if(direction == 2){
leftSpeed = speed;
rightSpeed = -speed;
}else if(direction == 3){
leftSpeed = -speed;
rightSpeed = -speed;
}else if(direction == 4){
leftSpeed = speed;
rightSpeed = speed;
}
Encoder_1.setTarPWM(leftSpeed);
Encoder_2.setTarPWM(rightSpeed);
}

void _delay(float seconds) {
if(seconds < 0.0){
seconds = 0.0;
}
long endTime = millis() + seconds * 1000;
while(millis() < endTime) _loop();
}

void setup() {
TCCR1A = _BV(WGM10);
TCCR1B = _BV(CS11) | _BV(WGM12);
TCCR2A = _BV(WGM21) | _BV(WGM20);
TCCR2B = _BV(CS21);
attachInterrupt(Encoder_1.getIntNum(), isr_process_encoder1, RISING);
attachInterrupt(Encoder_2.getIntNum(), isr_process_encoder2, RISING);
randomSeed((unsigned long)(lightsensor_12.read() * 123456));
while(1) {

move(1, 100 / 100.0 * 255);
_delay(1);
move(1, 0);
_delay(1);

_loop();
}

}

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

void loop() {
_loop();
}

 

● Program in Python
  1. Install MegaPi Pro on Raspberry Pi, and connect the 180 optical encoder motor to the DC/encoder driver.
  2. Install the latest Makeblock library for Raspberry Pi, do a “pip3 install makeblock” in the command line, and then do an “upgrade” in the command line.
  3. Create a Python file suffixed with .py.
  4. Write a program in the Python file.
  5. Run the Python file, for example, “python123.py”.
Function description
Function Feature
EncoderMotor(port) Set a port to connect the DC/encoder motor. port: MegaPiPro.PORT1~MegaPiPro.PORT4
run(speed) Rotate at the specified speed. speed: rotation speed range: -180–180
move_to(position,speed,callback) Rotate to the specified position at the specified speed. position: target position speed: rotation speed (range: -180–180)
callback: callback is triggered when the target position is reached
set_home() Set the current position as the origin.
Example program 1:
After the following program runs, the encoder motor connected to port 1 for DC/encoder motor on MegaPi Pro rotates clockwise at the speed of 50 RPM for 2 seconds, stops rotating for 1 second, rotates anticlockwise at the speed of 50 RPM for 2 seconds, stops rotating for 1 second, and then repeats this process.

from time import sleep
from makeblock import MegaPiPro
board = MegaPiPro.create()
encoder = board.EncoderMotor(MegaPiPro.PORT1)
while True:
encoder.run(50)
sleep(2)
encoder.run(0)
sleep(1)
encoder.run(-50)
sleep(2)
encoder.run(0)
sleep(1)

 

Example program 2:
After the following program runs, the encoder motor connected to port 1 for DC/encoder motor on MegaPi Pro rotates to the target position.

10 lines (9 sloc) 274 Bytes
RawBlameHistory

from time import sleep
from makeblock import MegaPiPro
board = MegaPiPro.create()
encoder = board.EncoderMotor(MegaPiPro.PORT1)
position = 0
def on_finished(value):
position = 5000 - position
encoder.move_to(position,100,on_finished)

on_finished(position)

 

Wiring mode

● Connect electronic modules
Connect the 180 optical encoder motor to the port for encoder motor on the main control board or the port for encoder motor on the encoder motor driver by using the cable for 180 optical encoder motor.

806e8b6a-081a-4350-96dd-55a4f0a4777a.png

 

● Build the structure
The 180 optical encoder motor can be used to provide power or used as a part of the chassis of mBot Ranger. Its shaft is compatible with the plastic timing pulley 62T with step and the plastic timing pulley 90T with step on Maker’s Platform of Makeblock.

59fdc7c1-d1c8-40b5-abb7-192d156a69b7.png

 

Was this article helpful?
1 out of 2 found this helpful

Comments

0 comments

Please sign in to leave a comment.