Now i have some ( for me advanced ) questions.. I´m trying to figure out how to calculate and move the steppermotor with input from two different compass sensors. I would like some help with the calculations so i can implement that to my existing code.
Rotating sensor mount with an rotating sensor.
I´m quite stuck in my programming and should need some help with calculation.
I trying to figure out how to calculate (stepperAngle) when using 2 different functions.
The first thing i have to do when powering on the system is rotating the stepper manual with an joystick to an desierd angle and pointing the remoteAngle sensor in the same desierd angle,
i then longpress Button to set stepper1.setZero and save an value from remoteAngle and mountAngle ( remotAngleZero, mountAngleZero ) to have some reference values to work with.
Function 1: move stepper to the angle remoteAngle currently is. // The stepper motor should follow the remote compass sensor, so if i look att an specific angle the stepperAngle should rotate to this positon.
Function 2: Stepper should keep it´s postion if the sensormount rotates. //So if the mount rotates after function 2 is activated the stepper should adjust it´s positon to were it was when function 2 was activated.
// Stepper should rotate the offset from mountAngleZero and mountAngle if the mountAngle rotates.
I allso want the (stepperAngle) value be smart so the stepper will move the nearest way to Function 1 or Function 2 angle but be limited by the max -400 to 400 degrees movment from (stepper1Zero)
Hardware:
I have an wireless remote with an compass sensor (remoteAngle)
I have an sensormount with an stepper motor that rotates an shaft. The compass (mountAngle) is mounted on the stepper motormount.
float remoteAngle = 0; // sensorvalue from remote compass 0 - 360.00 This sensor can be mounted on my head or arm.
float mountAngle = 0; // senorvalue from sensor mount 0 - 360.00 This sensor is mounted to stepper motor mount. (will not rotate whit stepper motor shaft)
int stepperAngle = 0; // stepper motor will rotate to this positon, -400 to 400 is the rotation limmit.
float remotAngleZero 0; // Save Refrencepoint
float mountAngleZero 0; // Save Refrencepoint
stepper1.zero // stepper zero Refrencepoint.
stepper1.read // stepper current positon -400 to 400 0 when pointing forward
button // button to activate function 1 or 2.
void setup() {
}
void loop() {
// put your main code here, to run repeatedly:
}
Best Regards