22 * Simple example intended to help users find the zero offset and natural direction of the sensor.
33 *
44 * These values can further be used to avoid motor and sensor alignment procedure.
5- *
6- * motor.initFOC(zero_offset, sensor_direction);
5+ * To use these values add them to the code:");
6+ * motor.sensor_direction=Direction::CW; // or Direction::CCW
7+ * motor.zero_electric_angle=1.2345; // use the real value!
78 *
89 * This will only work for abosolute value sensors - magnetic sensors.
910 * Bypassing the alignment procedure is not possible for the encoders and for the current implementation of the Hall sensors.
@@ -44,6 +45,9 @@ void setup() {
4445 // set motion control loop to be used
4546 motor.controller = MotionControlType::torque;
4647
48+ // force direction search - because default is CW
49+ motor.sensor_direction = Direction::UNKNOWN;
50+
4751 // initialize motor
4852 motor.init ();
4953 // align sensor and start FOC
@@ -54,9 +58,16 @@ void setup() {
5458 Serial.println (" Sensor zero offset is:" );
5559 Serial.println (motor.zero_electric_angle , 4 );
5660 Serial.println (" Sensor natural direction is: " );
57- Serial.println (motor.sensor_direction == 1 ? " Direction::CW" : " Direction::CCW" );
61+ Serial.println (motor.sensor_direction == Direction::CW ? " Direction::CW" : " Direction::CCW" );
62+
63+ Serial.println (" To use these values add them to the code:" );
64+ Serial.print (" motor.sensor_direction=" );
65+ Serial.print (motor.sensor_direction == Direction::CW ? " Direction::CW" : " Direction::CCW" );
66+ Serial.println (" ;" );
67+ Serial.print (" motor.zero_electric_angle=" );
68+ Serial.print (motor.zero_electric_angle , 4 );
69+ Serial.println (" ;" );
5870
59- Serial.println (" To use these values provide them to the: motor.initFOC(offset, direction)" );
6071 _delay (1000 );
6172 Serial.println (" If motor is not moving the alignment procedure was not successfull!!" );
6273}
0 commit comments