Skip to content

Commit

Permalink
V3.25 change:
Browse files Browse the repository at this point in the history
1.Mbot /ranger adds the function of communication variables.
2.Solve the blocking problem of 9g steering gear.
3.Solve the problem that the intelligent steering gear cannot read back the parameters.
4.Add version number function.
5.High power code motor reinforcement version query function.
6.Solve the problem that MeCompass will hang dead on 7 or 8 ports in Orion.
7.Solve the problem of SetColor (uint8_t index, long value) function error in mergharp.cpp.
8.Solve the problem that the function getPointFast() in the MeHumitureSensor. CPP cannot output the value normally.
9.The mBot board cannot extinguish the RGB. First upload the program with the RGB in any color, and then upload the program with the RGB in all colors. The RGB cannot extinguish (MeRGBLed bled. CPP file).
10.In the MegaPi firmware, SLOT1 is changed to slot_num instead of parameter transmission in the command processing stepper motor.
  • Loading branch information
MrHezhisheng committed Jan 4, 2019
1 parent 62f9342 commit 2b4214c
Show file tree
Hide file tree
Showing 12 changed files with 1,529 additions and 76 deletions.
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Makeblock Library v3.25
# Makeblock Library v3.26

Arduino Library for Makeblock Electronic Modules

Expand Down Expand Up @@ -28,13 +28,17 @@ If you have a discussion about licensing issues, please contact me (myan@makeblo

### How to use:

1. Download the source from the git https://codeload.github.com/Makeblock-official/Makeblock-Libraries/zip/master
1. Download the source from the git https://github.com/Makeblock-official/Makeblock-Libraries

2. In the Arduino IDE: "Sketch-> Include Library-> Add .ZIP Library-> select the downloaded file-> Open"
2. copy the makeblock folder to your arduino default library. Your Arduino library folder should now look like this
(on Windows): [arduino installation directory]\libraries\makeblock\src
(on MACOS): [arduino Package Contents]\contents\Java\libraries\makeblock\src

3. Click "File-> Examples". Here are some test programs in "MakeBlockDrive->"
3. Open the Arduino Application. (If it's already open, you will need to restart it to see changes.)

4. Depending on the type of board you're using, you need to modify the header file to match.
4. Click "File-> Examples". Here are some test programs in "MakeBlockDrive->"

5. Depending on the type of board you're using, you need to modify the header file to match.
For example, if you're using a mCore. You should change `#include <MeOrion.h>` to `#include <MeMCore.h>`
Corresponding boards and there header file are:

Expand Down
25 changes: 13 additions & 12 deletions examples/Firmware_for_MegaPi/Firmware_for_MegaPi.ino
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* Mark Yan 2017/03/01 0e.01.013 fix RGB lights issue.
* Mark Yan 2017/06/21 0e.01.014 fix JIRA issue 668 710.
* Mark Yan 2018/01/03 0e.01.015 add the absolute motor move for encode motor & add new stepper command.
* Payton 2019/01/02 0e.01.016 in new stepper command, change SLOT1 to slot_num.
**************************************************************************/
#include <Arduino.h>
#include <MeMegaPi.h>
Expand Down Expand Up @@ -171,7 +172,7 @@ boolean start_flag = false;
boolean move_flag = false;
boolean blink_flag = false;

String mVersion = "0e.01.015";
String mVersion = "0e.01.016";
//////////////////////////////////////////////////////////////////////////////////////
float RELAX_ANGLE = -1; //Natural balance angle,should be adjustment according to your own car
#define PWM_MIN_OFFSET 0
Expand Down Expand Up @@ -1423,32 +1424,32 @@ void runModule(uint8_t device)
int16_t speed_temp = readShort(12);
maxSpeed = abs(speed_temp);

steppers[SLOT1 - 1] = MeStepperOnBoard(slot_num);
initStepper(SLOT1 - 1,maxSpeed);
steppers[SLOT1 - 1].move(pos_temp,extID,stepper_move_finish_callback);
steppers[slot_num - 1] = MeStepperOnBoard(slot_num);
initStepper(slot_num - 1,maxSpeed);
steppers[slot_num - 1].move(pos_temp,extID,stepper_move_finish_callback);
}
if(STEPPER_SPEED_MOTION == subcmd)
{
int16_t speed_temp = readShort(8);

steppers[SLOT1 - 1] = MeStepperOnBoard(slot_num);
initStepper(SLOT1 - 1,speed_temp);
steppers[SLOT1 - 1].setSpeed(speed_temp);
steppers[slot_num - 1] = MeStepperOnBoard(slot_num);
initStepper(slot_num - 1,speed_temp);
steppers[slot_num - 1].setSpeed(speed_temp);
}
if(STEPPER_POS_MOTION_MOVETO == subcmd)
{
long pos_temp = readLong(8);
int16_t speed_temp = readShort(12);
maxSpeed = abs(speed_temp);

steppers[SLOT1 - 1] = MeStepperOnBoard(slot_num);
initStepper(SLOT1 - 1,maxSpeed);
steppers[SLOT1 - 1].moveTo(pos_temp,extID,stepper_move_finish_callback);
steppers[slot_num - 1] = MeStepperOnBoard(slot_num);
initStepper(slot_num - 1,maxSpeed);
steppers[slot_num - 1].moveTo(pos_temp,extID,stepper_move_finish_callback);
}
else if(STEPPER_SET_CUR_POS_ZERO == subcmd)
{
steppers[SLOT1 - 1] = MeStepperOnBoard(slot_num);
steppers[SLOT1 - 1].setCurrentPosition(0);
steppers[slot_num - 1] = MeStepperOnBoard(slot_num);
steppers[slot_num - 1].setCurrentPosition(0);
}
}
break;
Expand Down
1 change: 1 addition & 0 deletions src/MeAuriga.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
#include "MePS2.h"
#include "MePm25Sensor.h"
#include "MeColorSensor.h"
#include "MeSuperVariable.h"
/********************* Auriga Board GPIO Map *********************************/
// struct defined in MeAuriga.h
MePort_Sig mePort[17] =
Expand Down
27 changes: 27 additions & 0 deletions src/MeEncoderNew.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
#define CMD_GET_RATIO 0x25
#define CMD_GET_PULSE 0x26
#define CMD_GET_LOCK_STATE 0x27
#define CMD_GET_FIRWARE_VERSION 0x30

/**
* Alternate Constructor which can call your own function to map the Encoder Motor New to arduino port,
Expand Down Expand Up @@ -794,3 +795,29 @@ boolean MeEncoderNew::isTarPosReached(void)
lock_state = *(boolean*)buf;
return lock_state;
}

/**
* \par Function
* getFirmwareVersion
* \par Description
* Get Firmware Version, Only support EncodeDriver-V2.1.0 module firmware
* \param[in]
* None
* \par Output
* buffer: for storage version, length greater than 8
* \return
* None
* \par Others
*/
void MeEncoderNew::getFirmwareVersion(char *buffer)
{
Wire.beginTransmission(address);
Wire.write(_slot);
Wire.write(CMD_GET_FIRWARE_VERSION);
Wire.endTransmission(0);
Wire.requestFrom(address,(uint8_t)8);
for(int i=0;i<8;i++)
{
buffer[i] = Wire.read();
}
}
15 changes: 15 additions & 0 deletions src/MeEncoderNew.h
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,21 @@ class MeEncoderNew{
*/
boolean isTarPosReached(void);

/**
* \par Function
* getFirmwareVersion
* \par Description
* Get Firmware Version, Only support EncodeDriver-V2.1.0 module firmware
* \param[in]
* None
* \par Output
* buffer: for storage version, length greater than 8
* \return
* None
* \par Others
*/
void getFirmwareVersion(char *buffer);

private:
/**
* \par Function
Expand Down
1 change: 1 addition & 0 deletions src/MeMCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
#include "MeGasSensor.h"
#include "MePS2.h"
#include "MeColorSensor.h"
#include "MeSuperVariable.h"
/********************* Mbot Board GPIO Map *********************************/
MePort_Sig mePort[17] =
{
Expand Down
68 changes: 59 additions & 9 deletions src/MeRGBLed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* \brief Driver for W2812 full-color LED.
* @file MeRGBLed.cpp
* @author MakeBlock
* @version V1.0.1
* @date 2016/9/20
* @version V1.0.2
* @date 2017/06/23
* @brief Driver for W2812 full-color LED lights
*
* \par Copyright
Expand All @@ -31,17 +31,19 @@
* 3. void MeRGBLed::setpin(uint8_t port)
* 4. uint8_t MeRGBLed::getNumber()
* 5. cRGB MeRGBLed::getColorAt(uint8_t index)
* 6. bool MeRGBLed::setColorAt(uint8_t index, uint8_t red, uint8_t green, uint8_t blue)
* 7. bool MeRGBLed::setColor(uint8_t index, uint8_t red, uint8_t green, uint8_t blue)
* 8. bool MeRGBLed::setColor(uint8_t red, uint8_t green, uint8_t blue)
* 9. bool MeRGBLed::setColor(uint8_t index, long value)
* 10. void MeRGBLed::show()
* 6. void MeRGBLed::fillPixelsBak(uint8_t red, uint8_t green, uint8_t blue)
* 7. bool MeRGBLed::setColorAt(uint8_t index, uint8_t red, uint8_t green, uint8_t blue)
* 8. bool MeRGBLed::setColor(uint8_t index, uint8_t red, uint8_t green, uint8_t blue)
* 9. bool MeRGBLed::setColor(uint8_t red, uint8_t green, uint8_t blue)
* 10. bool MeRGBLed::setColor(uint8_t index, long value)
* 11. void MeRGBLed::show()
*
* \par History:
* <pre>
* `<Author>` `<Time>` `<Version>` `<Descr>`
* Mark Yan 2015/09/01 1.0.0 Rebuild the old lib.
* Scott 2016/09/20 1.0.1 Add a delay.
* Mark Yan 2017/06/23 1.0.2 Add function fillPixelsBak.
* </pre>
*
* @example ColorLoopTest.ino
Expand Down Expand Up @@ -202,6 +204,7 @@ void MeRGBLed::reset(uint8_t port)
s2 = mePort[port].s2;
s1 = mePort[port].s1;
setColor(0,0,0,0);
fillPixelsBak(0,2,1);
pinMask = digitalPinToBitMask(s2);
ws2812_port = portOutputRegister(digitalPinToPort(s2) );
pinMode(s2, OUTPUT);
Expand Down Expand Up @@ -230,6 +233,7 @@ void MeRGBLed::reset(uint8_t port,uint8_t slot)
s2 = mePort[port].s2;
s1 = mePort[port].s1;
setColor(0,0,0,0);
fillPixelsBak(0,2,1);
if(SLOT2 == slot)
{
pinMask = digitalPinToBitMask(s2);
Expand Down Expand Up @@ -261,6 +265,7 @@ void MeRGBLed::reset(uint8_t port,uint8_t slot)
void MeRGBLed::setpin(uint8_t port)
{
setColor(0,0,0,0);
fillPixelsBak(0,2,1);
pinMask = digitalPinToBitMask(port);
ws2812_port = portOutputRegister(digitalPinToPort(port) );
pinMode(port, OUTPUT);
Expand Down Expand Up @@ -294,6 +299,16 @@ void MeRGBLed::setNumber(uint8_t num_leds)
{
pixels[i] = 0;
}

pixels_bak = (uint8_t*)malloc(count_led * 3);
if(!pixels_bak)
{
printf("There is not enough space!\r\n");
}
for(int16_t i = 0; i < count_led * 3; i++)
{
pixels_bak[i] = 0;
}
}

/**
Expand Down Expand Up @@ -343,6 +358,35 @@ uint8_t MeRGBLed::getNumber(void)
return(count_led);
}

/**
* \par Function
* fillPixelsBak
* \par Description
* fill the LED color data to pixels_bak.
* \param[in]
* red - Red values
* \param[in]
* green - green values
* \param[in]
* blue - blue values
* \par Output
* None
* \return
* None
* \par Others
* None
*/
void MeRGBLed::fillPixelsBak(uint8_t red, uint8_t green, uint8_t blue)
{
for(int16_t i = 0; i < count_led; i++)
{
uint8_t tmp = i * 3;
pixels_bak[tmp] = green;
pixels_bak[tmp + 1] = red;
pixels_bak[tmp + 2] = blue;
}
}

/**
* \par Function
* setColorAt
Expand Down Expand Up @@ -661,8 +705,12 @@ void MeRGBLed::rgbled_sendarray_mask(uint8_t *data, uint16_t datlen, uint8_t mas
*/
void MeRGBLed::show(void)
{
rgbled_sendarray_mask(pixels, 3 * count_led, pinMask, (uint8_t*)ws2812_port);
delay(1);
if(memcmp(pixels_bak,pixels,3 * count_led) != 0)
{
rgbled_sendarray_mask(pixels, 3 * count_led, pinMask, (uint8_t*)ws2812_port);
memcpy(pixels_bak,pixels,3 * count_led);
delayMicroseconds(500);
}
}

/**
Expand All @@ -672,5 +720,7 @@ MeRGBLed::~MeRGBLed(void)
{
free(pixels);
pixels = NULL;
free(pixels_bak);
pixels_bak = NULL;
}

37 changes: 30 additions & 7 deletions src/MeRGBLed.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* \brief Driver for W2812 full-color LED lights.
* @file MeRGBLed.h
* @author MakeBlock
* @version V1.0.0
* @date 2015/09/01
* @version V1.0.1
* @date 2017/06/23
* @brief Header for MeRGBLed.cpp module
*
* \par Copyright
Expand All @@ -31,16 +31,18 @@
* 3. void MeRGBLed::setpin(uint8_t port)
* 4. uint8_t MeRGBLed::getNumber()
* 5. cRGB MeRGBLed::getColorAt(uint8_t index)
* 6. bool MeRGBLed::setColorAt(uint8_t index, uint8_t red, uint8_t green, uint8_t blue)
* 7. bool MeRGBLed::setColor(uint8_t index, uint8_t red, uint8_t green, uint8_t blue)
* 8. bool MeRGBLed::setColor(uint8_t red, uint8_t green, uint8_t blue)
* 9. bool MeRGBLed::setColor(uint8_t index, long value)
* 10. void MeRGBLed::show()
* 6. void MeRGBLed::fillPixelsBak(uint8_t red, uint8_t green, uint8_t blue)
* 7. bool MeRGBLed::setColorAt(uint8_t index, uint8_t red, uint8_t green, uint8_t blue)
* 8. bool MeRGBLed::setColor(uint8_t index, uint8_t red, uint8_t green, uint8_t blue)
* 9. bool MeRGBLed::setColor(uint8_t red, uint8_t green, uint8_t blue)
* 10. bool MeRGBLed::setColor(uint8_t index, long value)
* 11. void MeRGBLed::show()
*
* \par History:
* <pre>
* `<Author>` `<Time>` `<Version>` `<Descr>`
* Mark Yan 2015/09/01 1.0.0 Rebuild the old lib.
* Mark Yan 2017/06/23 1.0.1 Add function fillPixelsBak.
* </pre>
*
* DERIVED FROM
Expand Down Expand Up @@ -239,6 +241,26 @@ class MeRGBLed : public MePort
*/
cRGB getColorAt(uint8_t index);

/**
* \par Function
* fillPixelsBak
* \par Description
* fill the LED color data to pixels_bak.
* \param[in]
* red - Red values
* \param[in]
* green - green values
* \param[in]
* blue - blue values
* \par Output
* None
* \return
* None
* \par Others
* None
*/
void fillPixelsBak(uint8_t red, uint8_t green, uint8_t blue);

/**
* \par Function
* setColorAt
Expand Down Expand Up @@ -356,6 +378,7 @@ bool setColorAt(uint8_t index, uint8_t red, uint8_t green, uint8_t blue);
private:
uint16_t count_led;
uint8_t *pixels;
uint8_t *pixels_bak;

/**
* \par Function
Expand Down
Loading

0 comments on commit 2b4214c

Please sign in to comment.