I am working on the balancing robot, Can anyone help?

I have the Ultimate 2.0 robot kit from Make Block. I am working with the balancing robot. The sample program balances but drifts forward. Joop Brokking has a program for the balancing robot that does not use any libraries. By combining the two I should be able to have enough control to solve my problem. To adjust the program, I must bypass some of the Makeblock libraries to have access to the code and variables. My project is to configure the code without calling the libraries “MeMegaPi.h”, “MeGyro.h” or “MeGyro.cpp”. “MeMegaPi.h” consists mostly of INCLUDES. “MeGyro.h” establishes the DEFINEs and variables. And “MeGyro.cpp” contains the code for the gyro. At this point, I am trying to replace the library call to Gyrobegin() without success. I have transferred the DEFINEs, the variables, and the code to the main program. But, I can not remove the Gyro.begin() command.

Does anyone have an idea what I may have missed?

MeGyro.cpp (14.7 KB)

MeGyro.h (10.2 KB)

MeMegaPi.h (3.96 KB)

Balancing_Robot_7_27_2018B.ino (285 KB)

Will not compile. Missing MeMegaPiDCMotor.h.

Also, you're asking for help to modify commercial code. Regardless of it being open source, the intent of this forum is to offer assistance to you with respect to your code. Your query might be better placed in Project Guidance or Gigs and Collaborations.

If you want to start building from scratch, that's a different story. In that case, round up all the technical specs, post our first cut at fresh code and let's take it from there. I'd be glad to help, but not hacking commercial code. Having looked at their code I can't say I'm too impressed.

I MAY have a suggestion that this message should be moved from the "Programming Questions" section of the forum to "Project Guidance". I tried to do that but got a severe warning about cross-posting. So I will leave this thread here. If any one of the moderators believes this thread should be in another section, I will leave it to that moderator to move it. Realize that there may be a post in Project Guidance (if it has not been deleted).

It is NOT my intent to cross-post or duplicate or bump. However, I wonder if my response to the last post has been deleted. I assume here that it has in fact been deleted or is otherwise in a different section. Please forgive me for including my response for the first time in this section.

"post our first cut at fresh code"?
I have been through the theory of the balancing robot. It is not possible on the Lego in leJOS. leJOS is an implementation of Java and includes Garbage Collection. The Garbage Collection interferes with the real-time processing and causes the robot to fall.
The Make Block Ultimate 2.0 Kit mainboard uses the ATMEGA2560-16AU chip.
"Programming for all experience levels, Block-based programming software enables you to program your Ultimate 2.0 by simply dragging and dropping function blocks. Also supported are the Arduino IDE, NodeJS, and Python programming languages. This gives you a smooth learning curve on your way from beginner to expert coder."
So, the board is either Arduino(clone) or so close as to be indistinguishable. The 3-Axis Accelerometer and Gyro Sensor is the MPU-6050. I have the data sheet(book) for both the 2560 and the 6050. Make Block's libraries are skeleton code only sufficient to get a program to run. Joop Brokking's code uses no libraries but does use stepper motors, but I have encoder motors. With these resources, I should be able to write from scratch(relying heavily on resources) the code to make this build balance.

I have a caution about using the MakeBlock libraries. So, I am removing the calls to them and replacing with code. Even Joop Brokking is using the Wire.h library! So I am leaving that library active. I have included the MegaPi2560 library files here for reference. My program compiles without error at this point yet does not function. I have more to learn and write.

MeMegaPiDCMotor.cpp (8.04 KB)

MeMegaPiDCMotor.h (4.04 KB)

Balancing_Robot_7_27_2018B.ino (328 KB)