Encoder motor code not working


#1

Thank you from tech support for the suggestions:)

I am still trying however to get a motor to work. We have a class of students waiting to use the robots!! PLEASE CONTINUE TO HELP

Again here is a link to the micro controller and motor

Here is the code I am using:

#include <MeMegaPi.h>

MeEncoderOnBoard Encoder_1(SLOT4);
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(7);
Encoder_2.setPulse(7);
Encoder_1.setRatio(26.9);
Encoder_2.setRatio(26.9);
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);
}

void loop()
{
if(Serial.available())
{
char a = Serial.read();
switch(a)
{
case ‘0’:
Encoder_1.moveTo(0,300);
Encoder_2.moveTo(0,300);
break;
case ‘1’:
Encoder_1.moveTo(360,300);
Encoder_2.moveTo(-360,300);
break;
case ‘2’:
Encoder_1.moveTo(1800,300);
Encoder_2.moveTo(-1800,300);
break;
case ‘3’:
Encoder_1.moveTo(3600,50);
Encoder_2.moveTo(-3600,300);
break;
case ‘4’:
Encoder_1.moveTo(-360,50);
Encoder_2.moveTo(360);
break;
case ‘5’:
Encoder_1.moveTo(-1800,50);
Encoder_2.moveTo(1800,50);
break;
case ‘6’:
Encoder_1.moveTo(-3600,50);
Encoder_2.moveTo(3600,50);
break;
default:
break;
}
}
Encoder_1.loop();
Encoder_2.loop();
Serial.print(“Spped 1:”);
Serial.print(Encoder_1.getCurrentSpeed());
Serial.print(" ,Spped 2:");
Serial.print(" ,CurPos 1:");
Serial.print(Encoder_1.getCurPos());
Serial.print(" ,CurPos 2:");
Serial.println(Encoder_2.getCurPos());
}

HERE ARE THE WARNING MESSAGES WE ARE RECEIVING:

In file included from C:\Program Files (x86)\Arduino\libraries\makeblock\src/MeMegaPi.h:65:0,

             from C:\Program Files (x86)\Arduino\libraries\makeblock\examples\Me_On_Board_encoder\Me_Megapi_encoder_pid_pos\Me_Megapi_encoder_pid_pos.ino:32:

C:\Program Files (x86)\Arduino\libraries\makeblock\src/MeStepperOnBoard.h:73:0: warning: “SLOT_1” redefined

#define SLOT_1 1

^

In file included from C:\Program Files (x86)\Arduino\libraries\makeblock\src/Me7SegmentDisplay.h:70:0,

             from C:\Program Files (x86)\Arduino\libraries\makeblock\src/MeMegaPi.h:42,

             from C:\Program Files (x86)\Arduino\libraries\makeblock\examples\Me_On_Board_encoder\Me_Megapi_encoder_pid_pos\Me_Megapi_encoder_pid_pos.ino:32:

C:\Program Files (x86)\Arduino\libraries\makeblock\src/MePort.h:108:0: note: this is the location of the previous definition

#define SLOT_1 SLOT1

^

In file included from C:\Program Files (x86)\Arduino\libraries\makeblock\src/MeMegaPi.h:65:0,

             from C:\Program Files (x86)\Arduino\libraries\makeblock\examples\Me_On_Board_encoder\Me_Megapi_encoder_pid_pos\Me_Megapi_encoder_pid_pos.ino:32:

C:\Program Files (x86)\Arduino\libraries\makeblock\src/MeStepperOnBoard.h:74:0: warning: “SLOT_2” redefined

#define SLOT_2 2

^

In file included from C:\Program Files (x86)\Arduino\libraries\makeblock\src/Me7SegmentDisplay.h:70:0,

             from C:\Program Files (x86)\Arduino\libraries\makeblock\src/MeMegaPi.h:42,

             from C:\Program Files (x86)\Arduino\libraries\makeblock\examples\Me_On_Board_encoder\Me_Megapi_encoder_pid_pos\Me_Megapi_encoder_pid_pos.ino:32:

C:\Program Files (x86)\Arduino\libraries\makeblock\src/MePort.h:109:0: note: this is the location of the previous definition

#define SLOT_2 SLOT2

^

In file included from C:\Program Files (x86)\Arduino\libraries\makeblock\src/MeMegaPi.h:65:0,

             from C:\Program Files (x86)\Arduino\libraries\makeblock\examples\Me_On_Board_encoder\Me_Megapi_encoder_pid_pos\Me_Megapi_encoder_pid_pos.ino:32:

C:\Program Files (x86)\Arduino\libraries\makeblock\src/MeStepperOnBoard.h:75:0: warning: “SLOT_3” redefined

#define SLOT_3 3

^

In file included from C:\Program Files (x86)\Arduino\libraries\makeblock\src/Me7SegmentDisplay.h:70:0,

             from C:\Program Files (x86)\Arduino\libraries\makeblock\src/MeMegaPi.h:42,

             from C:\Program Files (x86)\Arduino\libraries\makeblock\examples\Me_On_Board_encoder\Me_Megapi_encoder_pid_pos\Me_Megapi_encoder_pid_pos.ino:32:

C:\Program Files (x86)\Arduino\libraries\makeblock\src/MePort.h:110:0: note: this is the location of the previous definition

#define SLOT_3 SLOT3

^

In file included from C:\Program Files (x86)\Arduino\libraries\makeblock\src/MeMegaPi.h:65:0,

             from C:\Program Files (x86)\Arduino\libraries\makeblock\examples\Me_On_Board_encoder\Me_Megapi_encoder_pid_pos\Me_Megapi_encoder_pid_pos.ino:32:

C:\Program Files (x86)\Arduino\libraries\makeblock\src/MeStepperOnBoard.h:76:0: warning: “SLOT_4” redefined

#define SLOT_4 4

^

In file included from C:\Program Files (x86)\Arduino\libraries\makeblock\src/Me7SegmentDisplay.h:70:0,

             from C:\Program Files (x86)\Arduino\libraries\makeblock\src/MeMegaPi.h:42,

             from C:\Program Files (x86)\Arduino\libraries\makeblock\examples\Me_On_Board_encoder\Me_Megapi_encoder_pid_pos\Me_Megapi_encoder_pid_pos.ino:32:

C:\Program Files (x86)\Arduino\libraries\makeblock\src/MePort.h:111:0: note: this is the location of the previous definition

#define SLOT_4 SLOT4

^

In file included from C:\Program Files (x86)\Arduino\libraries\makeblock\src/MeMegaPi.h:65:0,

             from C:\Program Files (x86)\Arduino\libraries\makeblock\examples\Me_On_Board_encoder\Me_Megapi_encoder_pid_pos\Me_Megapi_encoder_pid_pos.ino:32:

C:\Program Files (x86)\Arduino\libraries\makeblock\src/MeStepperOnBoard.h:77:0: warning: “SLOT1” redefined

#define SLOT1 SLOT_1

^

In file included from C:\Program Files (x86)\Arduino\libraries\makeblock\src/Me7SegmentDisplay.h:70:0,

             from C:\Program Files (x86)\Arduino\libraries\makeblock\src/MeMegaPi.h:42,

             from C:\Program Files (x86)\Arduino\libraries\makeblock\examples\Me_On_Board_encoder\Me_Megapi_encoder_pid_pos\Me_Megapi_encoder_pid_pos.ino:32:

C:\Program Files (x86)\Arduino\libraries\makeblock\src/MePort.h:104:0: note: this is the location of the previous definition

#define SLOT1 (1)

^

In file included from C:\Program Files (x86)\Arduino\libraries\makeblock\src/MeMegaPi.h:65:0,

             from C:\Program Files (x86)\Arduino\libraries\makeblock\examples\Me_On_Board_encoder\Me_Megapi_encoder_pid_pos\Me_Megapi_encoder_pid_pos.ino:32:

C:\Program Files (x86)\Arduino\libraries\makeblock\src/MeStepperOnBoard.h:78:0: warning: “SLOT2” redefined

#define SLOT2 SLOT_2

^

In file included from C:\Program Files (x86)\Arduino\libraries\makeblock\src/Me7SegmentDisplay.h:70:0,

             from C:\Program Files (x86)\Arduino\libraries\makeblock\src/MeMegaPi.h:42,

             from C:\Program Files (x86)\Arduino\libraries\makeblock\examples\Me_On_Board_encoder\Me_Megapi_encoder_pid_pos\Me_Megapi_encoder_pid_pos.ino:32:

C:\Program Files (x86)\Arduino\libraries\makeblock\src/MePort.h:105:0: note: this is the location of the previous definition

#define SLOT2 (2)

^

In file included from C:\Program Files (x86)\Arduino\libraries\makeblock\src/MeMegaPi.h:65:0,

             from C:\Program Files (x86)\Arduino\libraries\makeblock\examples\Me_On_Board_encoder\Me_Megapi_encoder_pid_pos\Me_Megapi_encoder_pid_pos.ino:32:

C:\Program Files (x86)\Arduino\libraries\makeblock\src/MeStepperOnBoard.h:79:0: warning: “SLOT3” redefined

#define SLOT3 SLOT_3

^

In file included from C:\Program Files (x86)\Arduino\libraries\makeblock\src/Me7SegmentDisplay.h:70:0,

             from C:\Program Files (x86)\Arduino\libraries\makeblock\src/MeMegaPi.h:42,

             from C:\Program Files (x86)\Arduino\libraries\makeblock\examples\Me_On_Board_encoder\Me_Megapi_encoder_pid_pos\Me_Megapi_encoder_pid_pos.ino:32:

C:\Program Files (x86)\Arduino\libraries\makeblock\src/MePort.h:106:0: note: this is the location of the previous definition

#define SLOT3 (3)

^

In file included from C:\Program Files (x86)\Arduino\libraries\makeblock\src/MeMegaPi.h:65:0,

             from C:\Program Files (x86)\Arduino\libraries\makeblock\examples\Me_On_Board_encoder\Me_Megapi_encoder_pid_pos\Me_Megapi_encoder_pid_pos.ino:32:

C:\Program Files (x86)\Arduino\libraries\makeblock\src/MeStepperOnBoard.h:80:0: warning: “SLOT4” redefined

#define SLOT4 SLOT_4

^

In file included from C:\Program Files (x86)\Arduino\libraries\makeblock\src/Me7SegmentDisplay.h:70:0,

             from C:\Program Files (x86)\Arduino\libraries\makeblock\src/MeMegaPi.h:42,

             from C:\Program Files (x86)\Arduino\libraries\makeblock\examples\Me_On_Board_encoder\Me_Megapi_encoder_pid_pos\Me_Megapi_encoder_pid_pos.ino:32:

C:\Program Files (x86)\Arduino\libraries\makeblock\src/MePort.h:107:0: note: this is the location of the previous definition

#define SLOT4 (4)

^

Sketch uses 11,964 bytes (4%) of program storage space. Maximum is 253,952 bytes.
Global variables use 1,420 bytes (17%) of dynamic memory, leaving 6,772 bytes for local variables. Maximum is 8,192 bytes.


#2

Hi sourtzis,

Here I compiled the example programs without error message.
Which version arduino software you are using?

Besides, you may refer to this document to add the latest verison makeblock library to your Arduino installation path.How can I add the Makeblock library to my Arduino IDE.zip (489.5 KB)


#3