The Project I am working on is trying to take the magnetometer and accelerometer (Adafruit LSM303LDHC). I'm working on a way to read elevation and azimuth angles so that I can point a ham radio antenna at satelites. I know that other people have better projects with more features than what I've come up with, but I'm doing this for an instrumentation class.
I'm getting errors that read
/tmp/233483053/sketch_apr29a/sketch_apr29a.ino:78:46: error: cannot convert 'double' to 'double*' for argument '1' to 'double vcross(double*, double*)'
double vec_e[3] = vcross(vec_a[3], vec_m[3]);
^
there are several occurances of this same error that are happening in the included excerpt. I have included the full code and all the errors as .txt files for portability.
double locVec[2];
double vec_x[3];
double vec_y[3];
double vec_z[3];
double vec_a[3] = {event.acceleration.x, event.acceleration.y, event.acceleration.z};
double vec_m[3] = {event.magnetic.x, event.magnetic.y, event.magnetic.z};
double vec_u[3] = { -vec_a[0], -vec_a[1], -vec_a[2]};
double vec_e[3] = vcross(vec_a[3], vec_m[3]);
double vec_n[3] = vcross(vec_e[3], vec_a[3]);
double vec_xyz[3];
vec_x[3] = vec_n[3];
vec_y[3] = vec_e[3];
vec_z[3] = vec_u[3];
double yu = dot(vec_y[3], vec_u[3]);
double xn = dot(vec_x[3], vec_n[3]);
double xe = dot(vec_x[3], vec_e[3]);
double zu = dot(vec_z[3], vec_u[3]);
locVec[0] = atan2(-xn, xe) + d;
locVec[1] = atan2(yu, zu);//output will be in radians and needs to be changed to degrees
//this is outside of void loop at the bottom
double vcross(double vec1[3], double vec2[3])
{
double vec_out[3];
vec_out[0] = vec1[1] * vec2[2] - vec1[2] * vec2[1];//x
vec_out[1] = vec1[2] * vec2[0] - vec1[0] * vec2[2];//y
vec_out[2] = vec1[0] * vec2[1] - vec1[1] * vec2[0];//z
return vec_out[3];
}
double dot(double vecA[3], double vecM[3])
{
double result;
result = vecA[0] * vecM[0] + vecA[1] * vecM[1] + vecA[2] * vecM[2];
return result;
}
Based on some of the research I've done, it sounds like the compiler is trying to convert the double into a pointer or something along those lines. That said, I have no idea what I am doing wrong nor do I know how to fix it.
Code.txt (4.34 KB)
Errors.txt (1.27 KB)
The function expects to be passed two pointers to arrays of doubles. You are simply passing two doubles. And the "doubles" you are passing are not even known values, since you are pulling them from the memory location AFTER the end of your arrays. You have arrays of length 3, which means they have elements 0, and 1, and 2. elements 3 does not exist.
Regards,
Ray L.
RayLivingston:
You have arrays of length 3, which means they have elements 0, and 1, and 2. elements 3 does not exist.
based on the example:
double vec_e[3] = vcross(vec_a[3], vec_m[3]);
in vec_a[3] I'm calling the third (nonexistent) element and not all three elements?How do I use the whole array and not have to pull each element of the array individually?
RayLivingston:
The function expects to be passed two pointers to arrays of doubles. You are simply passing two doubles.
so in the above example, it sounds like I need to declare at least two pointers that I then call and cycle through the steps to have them point at the arrays I need. Or could I just have the variable being used in the function point at the array? I'm honestly fairly new to pointers, so I'm uncertain what is best practice / what will work best.
edit: formatting
The array or structure name is a pointer, so the call arguments should be something like:
some_result = vcross(vec_a, vec_m);
C/C++ does not allow you to return an entire array from a function, so you need to declare structures, or a return array pointer in the call arguments.
My advice is to break down the parts you don't understand and get some simple working code to build up into your full project.
Using print statements so you'll know what's going on will make trouble shooting much easier.
Following is an example of what you might do to understand the function calls, you can run it and take a look at the serial monitor.
double vec_x[3];
double vec_y[3];
void setup() {
Serial.begin(9600);
vec_x[0] = 2.1;
vec_x[1] = 3.1;
vec_x[2] = 4.1;
vec_y[0] = 6.5;
vec_y[1] = 7.5;
vec_y[2] = 8.5;
Serial.println("In setup ");
Serial.print(" x: ");
Serial.print(vec_x[0]); Serial.print(", ");
Serial.print(vec_x[1]); Serial.print(", ");
Serial.println(vec_x[2]);
Serial.print(" y: ");
Serial.print(vec_y[0]); Serial.print(", ");
Serial.print(vec_y[1]); Serial.print(", ");
Serial.println(vec_y[2]);
vcross(vec_x, vec_y);
}
void loop() {
}
double vcross(double *vec1, double *vec2)
{
Serial.println("In setup ");
Serial.print(" 1: ");
Serial.print(vec1[0]); Serial.print(", ");
Serial.print(vec1[1]); Serial.print(", ");
Serial.println(vec1[2]);
Serial.print(" 2: ");
Serial.print(vec2[0]); Serial.print(", ");
Serial.print(vec2[1]); Serial.print(", ");
Serial.println(vec2[2]);
}