PaulS
I only ask that you slow down a little bit. I am at 20 posts with 1 every 5 minutes.
The script now runs as expected.
THANK YOU!
PaulS
I only ask that you slow down a little bit. I am at 20 posts with 1 every 5 minutes.
The script now runs as expected.
THANK YOU!
I am at 20 posts with 1 every 5 minutes.
The time between posts COULD be spent googling "how do I use my computer...". This is NOT the place to ask how to rename files, or how to change file extension hiding.
PaulS:
Geez. Can't we expect people to know how to do stupidly simple sh*t?
I have found it's less work in the end to assume nothing and just provide complete instructions. The people who already know can just skim over that stuff.
The level of computer literacy is dropping dramatically in recent years because many people don't own or use computers anymore since they can get by with their smartphones and tablets. I recently read an article about how tech companies are finding they need to do training of their new employees on the most basic things like how to double click with a mouse. It's really sad because we reached a point in the early 2000s where it was fairly common for each household to have a computer but now that's not the case. I have a relative who's just at the right age for me to introduce to Arduino but his family doesn't own a computer. The kid is constantly in front of a screen but not a device where you can do real work, only games and social media.
pert:
...The level of computer literacy is dropping dramatically in recent years because many people don't own or use computers anymore since they can get by with their smartphones and tablets.
blame Steve Jobs !!
the iPhone - for making smartphone->dumbperson
and the iPad - taking away the keyboard and minimising human access to the machine/tool.
the more advanced the "tool", the easier the "seller" gets to manipulate the "user" - just press the button, we will do the thinking for you - switch your brain off, you don't need it.
Some suggest that I spend time putting more information into my posts. Others suggest that I put more time into doing my own research. I did ask Mr. Google about extensions and Google does indeed have a lot of correct answers. In this case, the response was about Google extensions. It did not help. Sometimes it is necessary to know enough about the answer to ask the correct question. I don’t have any faith I artificial intelligence (Google Answers) at this level. There is no equivalent to the answer people on the forum. As long as I do not get PaulS too upset.
Now that the file naming issue is resolved, I am one step closer to my real project which is the balancing robot. I am not getting any response about my balancing robot project. It is too big a question. Perhaps I can get more interest if I focus on one of the smaller issues. It is my intent to take a step back (or a few) and look at the libraries. I can leave the standard libraries (and the MakeBlock libraries) in place and replace one of them with my own library. This will allow me to at least strip the standard library of unneeded code (for other boards).
Some library “#include” statements enclose the file name in <> and other statements use “”. In my case, I see both.
In Morse_Runtime_call.ino I have #include <Morse.h>
In Morse.cpp I have "Morse.h"
The “Morse.h” and “Morse.cpp” file combination is not a (or any part of any) standard library. I copied them from the Arduino website.
Arduino libraries are managed in three different places: inside the IDE installation folder, inside the core folder and in the libraries folder inside your sketchbook. The way libraries are chosen during compilation is designed to allow the update of libraries present in the distribution. This means that placing a library in the “libraries” folder in your sketchbook overrides the other libraries versions.
I seem to recall that <filename.h> is in one location and “filename.h” is in another location. So then why is Morse.h referred to in both ways?
CAN ANYONE PLEASE ADD SOME CLARITY TO THIS SUBJECT?
The #include <filename.h>
syntax causes all three of those locations to be searched for the file. The #include "filename.h"
syntax causes the local folder to be searched, then the other three library locations if it's not found in the local folder.
In this particular case, it would be possible to use either syntax without it causing any problems. However, the current syntax is most correct. Since Morse.h is, and always will be, in the same folder as Morse.cpp, it's most correct to use quotes. This also allows your library to be used outside the standard libraries folders, such as bundled with a sketch, where the <> syntax would not work. Since Morse.h is not in the same folder as Morse_Runtime_call.ino, it is most correct to use the <> syntax. There would be no point in the local folder being searched for a file you know isn't there.
You will often see very inconsistent use of the include syntax in Arduino code. I think it's worth taking the time to understand exactly what each syntax does and always use the most correct one, even if either would work.
THANK YOUR pert
In the development of my balancing robot project, I am currently working on the motors. MakeBlock has one mega library for my board (MeMegaPi2560 - AT MEGA 2560) that includes all of the remaining libraries. Put that aside for later. In my proposed special case for the balancing robot, there would be two libraries of the same name. Balancing_Robot_7_27_2018B would have its own customized version of MeMegaPiDCMotor.cpp(code)! This will allow me to remove the code for boards other than the one I have. I note that the definition of “current folder” is changing (instantaneously accurate). It sounds like the proper location for the custom library (.h & .cpp) would be right next to the program in the same folder and it would be referred to with #include “MeMegaPiDCMotor.h”!
Remember that the library for my board (MeMegaPi.h) includes all of the other libraries.
SO, IF I #INCLUDE MY CUSTOM LIBRARY SECOND, WILL THERE BE AN OVERWRITE OR A CONFLICT?
In other cases, where there is more than one library of the same name, it will be necessary to know the order of the search for that library and which library is implemented(First or Last).
I assume at this point that the search order is as follows . . .
#include <filename.h>
{
1. inside the IDE installation folder (C:\Program Files (x86)\Arduino\libraries)
2. inside the core folder and (?)
3. inside the libraries folder inside your sketchbook (C:\Users\CL_Plane_Guy\Documents\Arduino\libraries\Morse)
}
#include "filename.h"
{
1. inside the local folder (C:\Users\CL_Plane_Guy\Documents\Arduino\Morse_Runtine_call) or
(C:\Users\CL_Plane_Guy\Documents\GitHub\Balancing_Robot_7_27_2018B)
2. #include <filename.h>
}
AGAIN, THANK YOU FOR YOUR KNOWLEDGE, INTELLIGENCE AND TIME!
Morse.h (323 Bytes)
Morse.cpp (488 Bytes)
MeMegaPi.h (3.96 KB)
MeMegaPiDCMotor.h (4.04 KB)
MeMegaPiDCMotor.cpp (8.04 KB)
CLplaneguy:
This will allow me to remove the code for boards other than the one I have.
Why is that important to you?
CLplaneguy:
It sounds like the proper location for the custom library (.h & .cpp) would be right next to the program in the same folder and it would be referred to with #include “MeMegaPiDCMotor.h”!
You can do that if you like, but it's not required. The advantage of doing that is MeMegaPiDCMotor.h and MeMegaPiDCMotor.cpp will appear as tabs in the Arduino IDE and you can edit those files along with your sketch. This could also be seen as a disadvantage if you're not actively working on the files since it clutters up your sketch a bit.
The advantage of installing a library as usual under the libraries folder is that allows you to use the same copy of the library with multiple sketches. If you have a separate copy of the library in each sketch folder, and you want to make a change to the library, then you need to make that change multiple times.
CLplaneguy:
Remember that the library for my board (MeMegaPi.h) includes all of the other libraries.SO, IF I #INCLUDE MY CUSTOM LIBRARY SECOND, WILL THERE BE AN OVERWRITE OR A CONFLICT?
It will likely be no problem as long as you have an include guard in the library. In the Morse example library the include guard is the lines at the start:
#ifndef Morse_h
#define Morse_h
and at the end:
#endif
CLplaneguy:
I assume at this point that the search order is as follows . . .
#include <filename.h>
- inside the IDE installation folder (C:\Program Files (x86)\Arduino\libraries)
- inside the core folder and (?)
- inside the libraries folder inside your sketchbook (C:\Users\CL_Plane_Guy\Documents\Arduino\libraries\Morse)
No, the order is closer to this:
There are some other locations:
When multiple libraries contain the specified filename, the Arduino IDE gives priority to the one which has an architectures value in library.properties that matches the architecture of the currently selected board. If the library doesn't specify architectures then it defaults to wildcard, which has lower priority than an explicit architecture match. If the folder name matches the filename, that library is given higher priority.
Why is that important to you?
A smaller program is easier to understand and intelligently alter. That's all.
It will likely be no problem as long as you have an include guard in the library. In the Morse example library the include guard is the lines at the start:
Code: [Select]
#ifndef Morse_h
#define Morse_hand at the end:
Code: [Select]
#endif
I forgot about the include guard!!!!!
If I don't use any libraries, I can not do anything. If I use the libraries, I do not know exactly what is happening. My problem is to split the difference.
Specifically for my balancing robot, I am trying to understand the code to run my DC motor. MeMegaPi.h provides the code
megapi_dc_type megapi_dc_Port[14] =
{
{ NC, NC }, {33,32,11}, {40,41, 7}, {47,48, 6}, {A3,A2, 4},
{ NC, NC }, { NC, NC }, { NC, NC }, { NC, NC }, {35,34,12},
{36,37, 8}, {42,43, 9}, {A5,A4, 5},
};
and MeMegaPiDCMotor.cpp gives . . .
/**
* \par Function
* run
* \par Description
* Control the motor forward or reverse
* \param[in]
* speed - Speed value from -255 to 255
* \par Output
* None
* \return
* None
* \par Others
* None
*/
void MeMegaPiDCMotor::run(int16_t speed)
{
speed = speed > 255 ? 255 : speed;
speed = speed < -255 ? -255 : speed;
if(last_speed != speed)
{
last_speed = speed;
}
else
{
return;
}
if(speed > 0)
{
digitalWrite(_dc_dir_h2, LOW);
delayMicroseconds(5);
digitalWrite(_dc_dir_h1, HIGH);
analogWrite(_dc_pwm_pin,speed);
}
else if(speed < 0)
{
digitalWrite(_dc_dir_h1, LOW);
delayMicroseconds(5);
digitalWrite(_dc_dir_h2, HIGH);
analogWrite(_dc_pwm_pin,-speed);
}
else
{
digitalWrite(_dc_dir_h2, LOW);
digitalWrite(_dc_dir_h1, LOW);
analogWrite(_dc_pwm_pin,0);
}
}
This is the code that I am currently trying to decipher.
ANY ASSISTANCE WILL BE GREATLY APPRECIATED!
CLplaneguy:
A smaller program is easier to understand and intelligently alter. That's all.
That makes sense. Sometimes people spend a lot of time removing code out of a library to try to make it take less memory without realizing that unused code was being optimized away by the compiler anyway so I wanted to make sure that wasn't the reason.
I have trimmed the library code to run the MakeBlock wheels down to 15 lines. With the 15 lines, I can run both the left and right wheel. Now I am endeavoring to acquire the interest of a hardware expert to tell me what it means.
HOW AND WHY DOES THIS CODE POWER THE WHEELS.
void setup()
{
TCCR1A = _BV(WGM10);
TCCR1B = _BV(CS11) | _BV(CS10) | _BV(WGM12);//970hz
}
void loop()
{
//digitalWrite(_dc_dir_h2, LOW);
digitalWrite(34, LOW); // Left Wheel
delayMicroseconds(5);
//digitalWrite(_dc_dir_h1, HIGH);
digitalWrite(35, HIGH);
//analogWrite(_dc_pwm_pin,speed);
analogWrite(12, 100);
digitalWrite(37, LOW); // Right Wheel
delayMicroseconds(5);
digitalWrite(36, HIGH);
analogWrite(8, 100);
}
In working on the balancing robot, I have tried the Joop Brokking style of not including any libraries. I have eliminated arduino.h, MeMegaPi.h MeGyro.h, and MeMegaPiDCMotor.h! All works fine to this point. I have learned about the header files, data structures and about the structure of a library (.h & .cpp) and the structures of slots and ports. But, the balancing robot does not need a DC motor it needs an encoder motor. When I try to eliminate the library MeEncoderOnBoard! I am lost. It has 16 variables, 3 data structures, and 33 functions. 33 left and 33 right = 66! I reach the point of 3300 lines of code. The Arduino IDE gives me an error message of
Error compiling for board Arduino/Genuino Mega or Mega 2560.
If I had a line number I would figure it out. But a generic error message in 3300 lines is more than I can handle. At this point, I am at Chaos Theory. The more I change the more confusing it gets.
So, I wonder.
**Where does the error message come from? **
Is there an IDE that will give me more detail about the error and possibly a line number to look at?
Where does the error message come from?
WalMart.
Is there an IDE that will give me more detail about the error and possibly a line number to look at?
The Arduino IDE generated one or more error messages BEFORE that one. You start fixing problems at the top, NOT at the bottom.
I am combining several programs and libraries into one mega program. A generic error message could be caused by innumerable errors at the same time. I did look at the entire error list. Perhaps not soon enough! Finally, I commented out more and more code until the program compiled to completion. Sometimes causing an error in the process by not being careful with the commenting. Then I uncommented small blocks of needed code making sure that the syntax was correct and the program completed execution at every step. I learned some new (to me) syntax rules along the way. But, never did find a single error that was the cause of the original confusion. It is also possible that the original error is in the code that I never did uncomment. I don’t care. I uncommented the needed code. There is a lot of code in the libraries that does not suit my purpose. And I now know much more about the form of the libraries (.h & .cpp)! And, some library code is not intended to be in a program and will never work in a program.
MakeBlock does not document their libraries at all. So, now I must go through some MakeBlock libraries to find out what they do and how. Only then can I make intelligent choices about my next step.
THANK YOU PaulS
In the past, I was working with Lego and the Lego Gyro in Java but ran into garbage collection problems. Now I am working with MakeBlock (AT MEGA 2560-16AU) and the MPU-6050 in CPP! It seems that any gyro is initialized and then continually read.
The Lego Gyro is a one axis gyro that is initialized and continually recalibrated to account for drift with the following code . . .
private void updateGyroData() {
// TODO: The GyroSensor class actually rebaselines for drift ever 5 seconds. This not needed? Or is this method better?
// Some of this fine tuning may actually interfere with fine-tuning happening in the hardcoded dIMU and GyroScope code.
float gyroRaw;
gyroRaw = gyro.getAngularVelocity();
gOffset = EMAOFFSET * gyroRaw + (1-EMAOFFSET) * gOffset;
gyroSpeed = gyroRaw - gOffset; // Angular velocity (degrees/sec)
gAngleGlobal += gyroSpeed*tInterval;
gyroAngle = gAngleGlobal; // Absolute angle (degrees)
}
The MPU-6050 is a 3-axis gyro, 3-axis accelerometer, and thermometer that calculates the angle with the following code . . .
/**
* \par Function
* update
* \par Description
* Update some calculated angle values to the variable.
* \param[in]
* None
* \par Output
* None
* \return
* None
* \par Others
* The angle values are calculated by complementary filter.
* The time constant of filter is set to 0.5 second, but period dt is not a constant,
* so the filter coefficient will be calculated dynamically.
*/
void MeGyro::update(void)
{
static unsigned long last_time = 0;
int8_t return_value;
double dt, filter_coefficient;
/* read imu data */
return_value = readData(0x3b, i2cData, 14);
if(return_value != 0)
{
return;
}
double ax, ay, az;
/* assemble 16 bit sensor data */
accX = ( (i2cData[0] << 8) | i2cData[1] );
accY = ( (i2cData[2] << 8) | i2cData[3] );
accZ = ( (i2cData[4] << 8) | i2cData[5] );
gyrX = ( ( (i2cData[8] << 8) | i2cData[9] ) - gyrXoffs) / gSensitivity;
gyrY = ( ( (i2cData[10] << 8) | i2cData[11] ) - gyrYoffs) / gSensitivity;
gyrZ = ( ( (i2cData[12] << 8) | i2cData[13] ) - gyrZoffs) / gSensitivity;
ax = atan2(accX, sqrt( pow(accY, 2) + pow(accZ, 2) ) ) * 180 / 3.1415926;
ay = atan2(accY, sqrt( pow(accX, 2) + pow(accZ, 2) ) ) * 180 / 3.1415926;
dt = (double)(millis() - last_time) / 1000;
last_time = millis();
if(accZ > 0)
{
gx = gx - gyrY * dt;
gy = gy + gyrX * dt;
}
else
{
gx = gx + gyrY * dt;
gy = gy - gyrX * dt;
}
gz += gyrZ * dt;
gz = gz - 360 * floor(gz / 360);
if(gz > 180)
{
gz = gz - 360;
}
/*
complementary filter
set 0.5sec = tau = dt * A / (1 - A)
so A = tau / (tau + dt)
*/
filter_coefficient = 0.5 / (0.5 + dt);
gx = gx * filter_coefficient + ax * (1 - filter_coefficient);
gy = gy * filter_coefficient + ay * (1 - filter_coefficient);
}
My problem is that my robot creeps forward. Theoretically I could continually recalibrate the gyro with the Lego Gyro method. But, the MPU6050 calculates the angle continuously and presumably is correct. An improvement would assume the calculation is incorrect or drifts and needs recalibration. But, I am not seeing this improvement in the literature.
ANY COMMENTS WILL BE GREATLY APPRCIATED