Programming the Lepton from start to finish

It’s the 6th icon from the left above the text area. Looks like </> and the tooltip says “Preformatted text (Ctrl+E)”.

Lepton does not have enough flash for Commander. I wrote a quick and dirty serial communication interface via the Arduino IDE serial monitor, where you type single letter commands to read and write variables for tuning and debugging. Lowercase to output the current value, uppercase followed by a number to set the value and then print it for confirmation. Feel free to change the letters to whatever you prefer, or just use it as inspiration to make something better.

void SerialComm()
{
  switch(Serial.read())
  {
  case '?':
    Serial.print("sensor_direction ");
    Serial.print(motor.sensor_direction);
    Serial.print(", zero_electric_angle ");
    Serial.println(motor.zero_electric_angle);
    break;
  case 's': Serial.print("shaft_velocity "); Serial.println(motor.shaft_velocity); break;
  case 'a':
    Serial.print("shaft_angle ");
    Serial.print(motor.shaft_angle);
    Serial.print(", electric_rotations ");
    Serial.print(sensor.electric_rotations);
    Serial.print(", electric_sector ");
    Serial.println(sensor.electric_sector);
    break;
  case 'K': motor.KV_rating = Serial.parseFloat(); Serial.print("Set ");
  case 'k': Serial.print("kv "); Serial.println(motor.KV_rating); break;
  case 'R': motor.phase_resistance = Serial.parseFloat(); Serial.print("Set ");
  case 'r': Serial.print("phase_resistance "); Serial.println(motor.phase_resistance); break;
  case 'T': target_range = Serial.parseFloat(); Serial.print("Set ");
  case 't': Serial.print("target_range "); Serial.println(target_range); break;

  case 'V': motor.voltage_limit = Serial.parseFloat(); Serial.print("Set ");
  case 'v': Serial.print("motor.voltage_limit "); Serial.println(motor.voltage_limit); break;
  case 'C': motor.current_limit = motor.PID_velocity.limit = Serial.parseFloat(); Serial.print("Set ");
  case 'c': Serial.print("motor.current_limit "); Serial.println(motor.current_limit); break;

  case 'O': motor.PID_velocity.output_ramp = Serial.parseFloat(); Serial.print("Set ");
  case 'o': Serial.print("motor.PID_velocity.output_ramp "); Serial.println(motor.PID_velocity.output_ramp); break;
  case 'F': motor.LPF_velocity.Tf = Serial.parseFloat(); Serial.print("Set ");
  case 'f': Serial.print("motor.LPF_velocity.Tf "); Serial.println(motor.LPF_velocity.Tf); break;
  case 'P': motor.PID_velocity.P = Serial.parseFloat(); Serial.print("Set ");
  case 'p': Serial.print("motor.PID_velocity.P "); Serial.println(motor.PID_velocity.P); break;
  case 'I': motor.PID_velocity.I = Serial.parseFloat(); Serial.print("Set ");
  case 'i': Serial.print("motor.PID_velocity.I "); Serial.println(motor.PID_velocity.I); break;
  case 'D': motor.PID_velocity.D = Serial.parseFloat(); Serial.print("Set ");
  case 'd': Serial.print("motor.PID_velocity.D "); Serial.println(motor.PID_velocity.D); break;

  case 'W': motor.P_angle.P = Serial.parseFloat(); Serial.print("Set ");
  case 'w': Serial.print("motor.P_angle.P "); Serial.println(motor.P_angle.P); break;
  }
}
1 Like