It is not calculating the proper answer. It is not my sketch but was given to me to implement. It is part of a much larger sketch and I think that this is where it is going wrong.
When it gets to this statement:
pwm->setPWM(mip->servo_num, 0, mip->pos/US_PER_BIT);
The value of mip->pos should not be zero000.
The value of newpos coming into this routine is 22522
void Gimbal::setMotorPosition (uint8_t motn, uint16_t newpos)
{
MotorInfo *mip = &motor[motn];
mip->atmin = (newpos <= mip->min);
if (mip->atmin)
newpos = mip->min;
mip->atmax = (newpos >= mip->max);
if (mip->atmax)
newpos = mip->max;
mip->del_pos = (int)newpos - (int)mip->pos;
mip->pos = newpos;
pwm->setPWM(mip->servo_num, 0, mip->pos/US_PER_BIT);
The structure referenced is this:
typedef struct {
float az_scale, el_scale; // az and el scale: steps (del usec) per degree
uint16_t min, max; // position limits, usec
uint16_t pos; // last commanded position, usec
int16_t del_pos; // change in pos since previous move
bool atmin, atmax; // (would have been commanded to) limit
uint8_t servo_num; // I2C bus address 0..15
} MotorInfo;
And before I go off into google and try and figure out how to print the variables that are referenced by the structure and pointers, I would sure appreciate some guidance.
If I wanted to print min and max and az_scale, etc, what would the syntax be.
Serial.println(?????);
mega thanks
if you are using a pointer to the struct, it's Serial.print(mip->max); In your posted code, they have the motor structs in a lookup table. Do you want to continue with that approach?
aarg:
if you are using a pointer to the struct, it's Serial.print(mip->max);
Thank you, thank you, thank you.
Is this the statement that defines?, declares? identifies mip ?
MotorInfo *mip = &motor[motn];
aarg:
if you are using a pointer to the struct, it's Serial.print(mip->max); In your posted code, they have the motor structs in a lookup table. Do you want to continue with that approach?
I dont know enough about structures and pointers to comment on this guys approach/technique other than that it seems overly complicated. There are ever only 2 servo motors that are driven. They are used to position an antenna to track a satellite across the visible sky.
So, given the position of the satellite, start over there and follow it to here across the sky until it drops out of sight.
hextejas:
Is this the statement that defines?, declares? identifies mip ?
MotorInfo *mip = &motor[motn];
That Declares a variable named mip of type MotorInfo *
It also Defines the variable named mip of type MotorInfo *
It also initializes that variable to the address of motor[motn];
See: What's the difference between declaring and defining in C and C++ - Cprogramming.com
My preferred syntax to do the same thing would be:
MotorInfo *mip = motor + motn;