fiduciary

Author Topic: TeensySaber Software Discussion  (Read 67195 times)

0 Members and 1 Guest are viewing this topic.

Offline KanyonKris

  • Padawan Learner
  • **
  • Posts: 72
  • Um...Hello?
Re: TeensySaber Software Discussion
« Reply #270 on: February 06, 2018, 05:45:10 PM »
So I commented out the battery charge preset and the button work to turn it on and off but the clash does not work.... but clashh will trigger from the serial monitor but not the button... We are getting somewhere.
When you power up your saber boards, what does the Serial Monitor show? Specifically, does it say "Accel setup ... Done." or "Accell setup ... Failed."?
If it failed, try powering it again because sometimes it fails on power up randomly. If you power up 3 times and it fails every time, you probably have a hardware problem. We built our boards and 2-3 of them had these failures but reflowing the IMU IC fixed it.
« Last Edit: February 06, 2018, 06:53:25 PM by KanyonKris »

Offline profezzorn

  • Mining Colony Members
  • Master Force User
  • *
  • Posts: 901
  • May the source be with you.
    • Hubbe's Corner
Re: TeensySaber Software Discussion
« Reply #271 on: February 06, 2018, 07:46:12 PM »
So I commented out the battery charge preset and the button work to turn it on and off but the clash does not work.... but clashh will trigger from the serial monitor but not the button... We are getting somewhere.
When you power up your saber boards, what does the Serial Monitor show? Specifically, does it say "Accel setup ... Done." or "Accell setup ... Failed."?
If it failed, try powering it again because sometimes it fails on power up randomly. If you power up 3 times and it fails every time, you probably have a hardware problem. We built our boards and 2-3 of them had these failures but reflowing the IMU IC fixed it.

It's possible I broke something too. Or maybe gmcivor made some changes in the earlier version but forgot to make them in this version?
I will update my v1 saber when   I get a chance to make sure.

Offline gmcivor

  • Force User
  • ***
  • Posts: 140
  • Do or do not. There is no try.
Re: TeensySaber Software Discussion
« Reply #272 on: February 07, 2018, 08:02:48 AM »
Quote

It's possible I broke something too. Or maybe gmcivor made some changes in the earlier version but forgot to make them in this version?
I will update my v1 saber when   I get a chance to make sure.

I have had these blade configs and fonts set up for awhile and they have been transferring through great. When you updated the software to 1.175 I had the same button config problem since that is when it first changed but I changed the configuration settings and everything worked beautifully. Now that I have updated to 1.191 it doesn't seem to like it. I did some testing last night and everything works when I press the button but the clash. I can make the clash sound and go off from the serial monitor. It will cycle through presets and everything works as expected through serial monitor. Holding the button and clashing wont cause the clash and wont cause it to switch to the next preset. Even when I have the saber on and try to clash it will not trigger.

*** Update: Doing some more bench testing I put it in the hilt and turned it on and I discovered it doesn't detect swings either. I can move the saber around and it just plays the hum.... So clash and swing sounds do not work in hilt. On the bench I can make it play the clash sounds.

Regards,

GMcIvor
« Last Edit: February 07, 2018, 12:23:17 PM by gmcivor »

Offline miib123

  • No Force
  • *
  • Posts: 20
  • Um...Hello?
Re: TeensySaber Software Discussion
« Reply #273 on: February 07, 2018, 09:25:48 AM »
miib123, your wires look short enough.

In case you missed it, I agree with profezzorn, plug your microSD card into your computer and reformat it (mine is FAT23), then copy all the files back onto it and try it in your saber electronics. If that doesn't work, perhaps try a different microSD card.

Succes!!!!!!! It plays sound, when i type "play" command(FAT32 helped)! Super happy!!  :smiley: :smiley: :smiley: :smiley:

Now the next thing is to play the sounds, when i turn on the saber with a button. I followed the profezzorn's guide on his page but i'm little confused, how to load the sound into code. Could someone posted his code example, so i can copy it, please? I downloaded the smoothswing sound fonts but dont know, how to implement the code to react to power on/off, hum, swing and clash.

This is how my smoothswing (S2RD) folder looks like:





And my configuration in "common_presets" tab:



Thank you! :)


Offline profezzorn

  • Mining Colony Members
  • Master Force User
  • *
  • Posts: 901
  • May the source be with you.
    • Hubbe's Corner
Re: TeensySaber Software Discussion
« Reply #274 on: February 07, 2018, 09:43:06 AM »
miib123, your wires look short enough.

In case you missed it, I agree with profezzorn, plug your microSD card into your computer and reformat it (mine is FAT23), then copy all the files back onto it and try it in your saber electronics. If that doesn't work, perhaps try a different microSD card.

Succes!!!!!!! It plays sound, when i type "play" command(FAT32 helped)! Super happy!!  :smiley: :smiley: :smiley: :smiley:

Now the next thing is to play the sounds, when i turn on the saber with a button. I followed the profezzorn's guide on his page but i'm little confused, how to load the sound into code. Could someone posted his code example, so i can copy it, please? I downloaded the smoothswing sound fonts but dont know, how to implement the code to react to power on/off, hum, swing and clash.

This is how my smoothswing (S2RD) folder looks like:





And my configuration in "common_presets" tab:



Thank you! :)

All you should need to do is to change "fontdir" to "s2rd".

Offline KanyonKris

  • Padawan Learner
  • **
  • Posts: 72
  • Um...Hello?
Re: TeensySaber Software Discussion
« Reply #275 on: February 07, 2018, 10:01:54 AM »
Succes!!!!!!! It plays sound, when i type "play" command(FAT32 helped)! Super happy!!  :smiley: :smiley: :smiley: :smiley:

Now the next thing is to play the sounds, when i turn on the saber with a button. I followed the profezzorn's guide on his page but i'm little confused, how to load the sound into code. Could someone posted his code example, so i can copy it, please? I downloaded the smoothswing sound fonts but dont know, how to implement the code to react to power on/off, hum, swing and clash.

This is how my smoothswing (S2RD) folder looks like:
Good to hear you have sound playing. You can get sounds playing by fixing the paths in your presets or reorganizing the directory structure on your SD card. I recommend you restructure the files and directories, you don't need that many subdirectory levels.

profezzorn outlined the cleanest directory structure - TeensySaber Software Discussion

In your font directories (ie font01), don't have subfolders for each sound (ie /font01/hum, /font01/clash), even though some font packs are organized this way. Go into each subfolder and move the WAV files into the font directory. So you should have:
/font01/hum.wav
/font01/clash.wav
etc.

The tracks folder is for music (sound tracks) and it should be off the root folder, not inside each font folder, for example: /tracks might have: /tracks/cantina.wav

Now point your presets to the font you want to use:
  { "font01", "tracks/cantina.wav", StylePtr<InOutSparkTip<EasyBlade<BLUE, WHITE>, 300, 800> >(), "blue" },
So when this preset is active it will play the files found in /font01 when it needs a sound, for example to play the hum it will look for /font01/hum.wav or if you have /font01/hum01.wav and /font01/hum02.wav it will randomly select one of these 2 hums to play. Another example, when you turn on the saber it will try to play /font01/out.wav. And if you long press the power button it will play /tracks/cantina.wav as a background sound track.

Offline profezzorn

  • Mining Colony Members
  • Master Force User
  • *
  • Posts: 901
  • May the source be with you.
    • Hubbe's Corner
Re: TeensySaber Software Discussion
« Reply #276 on: February 07, 2018, 10:09:01 AM »
n your font directories (ie font01), don't have subfolders for each sound (ie /font01/hum, /font01/clash), even though some font packs are organized this way. Go into each subfolder and move the WAV files into the font directory. So you should have:
/font01/hum.wav
/font01/clash.wav
etc.

Why move the files?
sub-folders are totally supported

Offline KanyonKris

  • Padawan Learner
  • **
  • Posts: 72
  • Um...Hello?
Re: TeensySaber Software Discussion
« Reply #277 on: February 07, 2018, 12:23:32 PM »
Why move the files?
sub-folders are totally supported
That's good to know. When we were bringing up our boards I had a problem with sounds not playing that I attributed to a subdirectory issue, but I guess it wasn't.
« Last Edit: February 08, 2018, 03:43:28 PM by KanyonKris »

Offline KanyonKris

  • Padawan Learner
  • **
  • Posts: 72
  • Um...Hello?
Low power notification
« Reply #278 on: February 08, 2018, 06:32:01 PM »
profezzorn, the low power notification wasn't working so I fixed it. When the battery voltage drops too low it prints out a warning to the serial port and says "low power" every 10 seconds (10000 milliseconds).

Code: [Select]
    if (battery_monitor.low()) {
      if (current_preset_->style != &style_charging) {
        if (on_) {
          STDOUT.print("Turning off, low battery voltage: ");
          STDOUT.println(battery_monitor.battery());
          Off();
        } else if (millis() - last_beep_ > 10000) {
          STDOUT.print("Warning, low battery voltage: ");
          STDOUT.println(battery_monitor.battery());
#ifdef ENABLE_AUDIO
          // TODO: allow this to be replaced with WAV file
          talkie.Say(spLOW);
          talkie.Say(spPOWER);
//          beeper.Beep(1.0, 3000.0);
#endif
          last_beep_ = millis();
       }
      }
    }

While I was at it, I didn't like how often the battery voltage was reported to the serial port, so I added some code to only report when the voltage has changed by more than 0.05 volts:

Code: [Select]
    if (monitor.ShouldPrint(Monitoring::MonitorBattery) || millis() - last_print_millis_ > 5000) {
      if (v > last_print_voltage_ + 0.05 || v < max(last_print_voltage_ - 0.05, 0)) {
        STDOUT.print("Battery voltage: ");
        STDOUT.println(v);
        last_print_voltage_ = v;
      }
      last_print_millis_ = millis();
    }

BTW, I didn't see that the beeper class was turning on the amplifier, should this be the code?

Code: [Select]
  void Beep(float length, float freq) {
    digitalWrite(amplifierPin, HIGH); // turn on the amplifier
    x_ = f_ = AUDIO_RATE / freq / 2.0;
    samples_ = AUDIO_RATE * length;
  }

Last thing, why is the hum still playing (but no sound, I assume because the amp is off) when the saber is off (blade not on)?

Offline spearson

  • No Force
  • *
  • Posts: 20
  • Um...Hello?
Re: TeensySaber Software Discussion
« Reply #279 on: February 08, 2018, 07:29:29 PM »
If you're using a polyphonic font, there is a bug where the hum fades out but doesn't stop playing. This for me also left the amp on.

You can turn it off by hitting the aux button, or you can play around with bufferedwaveplayerstate (or something hum-state in the polyphonic class, I can't recall exactly), and force the wave player off when the hum has faded out. The latter is the workaround I used until he puts in a proper fix.
« Last Edit: February 08, 2018, 07:44:00 PM by spearson »

Offline profezzorn

  • Mining Colony Members
  • Master Force User
  • *
  • Posts: 901
  • May the source be with you.
    • Hubbe's Corner
Re: Low power notification
« Reply #280 on: February 08, 2018, 08:06:54 PM »
Nice!

profezzorn, the low power notification wasn't working so I fixed it. When the battery voltage drops too low it prints out a warning to the serial port and says "low power" every 10 seconds (10000 milliseconds).

Code: [Select]
    if (battery_monitor.low()) {
      if (current_preset_->style != &style_charging) {
        if (on_) {
          STDOUT.print("Turning off, low battery voltage: ");
          STDOUT.println(battery_monitor.battery());
          Off();
        } else if (millis() - last_beep_ > 10000) {
          STDOUT.print("Warning, low battery voltage: ");
          STDOUT.println(battery_monitor.battery());
#ifdef ENABLE_AUDIO
          // TODO: allow this to be replaced with WAV file
          talkie.Say(spLOW);
          talkie.Say(spPOWER);
//          beeper.Beep(1.0, 3000.0);
#endif
          last_beep_ = millis();
       }
      }
    }


Took me a while to figure out what you actually changed. Should be fixed now.

Quote

While I was at it, I didn't like how often the battery voltage was reported to the serial port, so I added some code to only report when the voltage has changed by more than 0.05 volts:

Code: [Select]
    if (monitor.ShouldPrint(Monitoring::MonitorBattery) || millis() - last_print_millis_ > 5000) {
      if (v > last_print_voltage_ + 0.05 || v < max(last_print_voltage_ - 0.05, 0)) {
        STDOUT.print("Battery voltage: ");
        STDOUT.println(v);
        last_print_voltage_ = v;
      }
      last_print_millis_ = millis();
    }

I kind of prefer to have it tell me fairly often, since I get paranoid when nothing happens for a long time.

Quote

BTW, I didn't see that the beeper class was turning on the amplifier, should this be the code?

Code: [Select]
  void Beep(float length, float freq) {
    digitalWrite(amplifierPin, HIGH); // turn on the amplifier
    x_ = f_ = AUDIO_RATE / freq / 2.0;
    samples_ = AUDIO_RATE * length;
  }


Good idea.

Quote
Last thing, why is the hum still playing (but no sound, I assume because the amp is off) when the saber is off (blade not on)?

First of all, when something like this happens, you can use "whatison" to figure out why.
Secondly, this is almost certainly because of a bug in the polyphonic font implementation that I've been meaning to fix for a while but not gotten around to, until now.

Unfortunately I don't have time to actually test stuff today (maybe laster), but I uploaded the latest version, which compiles, but is otherwise completely untested here:
http://fredrik.hubbe.net/lightsaber/lightsaber-1.201.zip


Offline KanyonKris

  • Padawan Learner
  • **
  • Posts: 72
  • Um...Hello?
Re: Low power notification
« Reply #281 on: February 08, 2018, 10:42:10 PM »
I kind of prefer to have it tell me fairly often, since I get paranoid when nothing happens for a long time.
That's true. I cooked up that code because sometimes I'd be annoyed when I scroll back through the serial monitor to study some previous output, and while I'm reading the battery voltage would spit out and cause the text to shift up. It was fun to twiddle with the code to see if I could make it do what I wanted. But the more pragmatic solution is to adjust the interval duration to taste.

Quote
First of all, when something like this happens, you can use "whatison" to figure out why.
Secondly, this is almost certainly because of a bug in the polyphonic font implementation that I've been meaning to fix for a while but not gotten around to, until now.
Good to know, thanks.

Quote
Unfortunately I don't have time to actually test stuff today (maybe laster), but I uploaded the latest version, which compiles, but is otherwise completely untested here:
http://fredrik.hubbe.net/lightsaber/lightsaber-1.201.zip
FYI, I tested the low power notification code a lot. I was running it on a Teensy 3.5 and I'd connect/disconnect the power sense resistor and make sure it reacted correctly.

Thanks for the updated code base.

One more thing, when I comment out #define ENABLE_AUDIO I get an error: 'BoxFilter' does not name a type
Looks like some BoxFilter code is up in that big chunk of code enclosed in an ENABLE_AUDIO #ifdef. I couldn't figure out how to fix it.

Offline profezzorn

  • Mining Colony Members
  • Master Force User
  • *
  • Posts: 901
  • May the source be with you.
    • Hubbe's Corner
Re: Low power notification
« Reply #282 on: February 09, 2018, 12:23:50 AM »
One more thing, when I comment out #define ENABLE_AUDIO I get an error: 'BoxFilter' does not name a type
Looks like some BoxFilter code is up in that big chunk of code enclosed in an ENABLE_AUDIO #ifdef. I couldn't figure out how to fix it.

The solution is just to move the BoxFilter template up to live next close to the other helper classes.
Eventually I'm going to create a "common" subdir and move a bunch of these things in there.
I uploaded a 202 version with this fix: http://fredrik.hubbe.net/lightsaber/lightsaber-1.202.zip
As soon as i get a chance to test things better, I'll make a update my site to point to this version.


Offline miib123

  • No Force
  • *
  • Posts: 20
  • Um...Hello?
Re: TeensySaber Software Discussion
« Reply #283 on: February 09, 2018, 05:34:54 AM »
I'm back from testing the device. But again, i have mixed thoughts. Today, it was planned to put the whole thing in to the prop shield but again, i encoutered a problem. First i rewired the whole thing and soldered the aviator plugs onto electronics, added booster and li-on battery, powered the electronics... and it worked - for a while. LEDs were powering on, the sound was working and i even managed to change the fonts. As i said, it worked for a while.

Now when i power on the saber, all i can hear is the quiet high frequency sound, comming from the speaker and no LEDs turning on. If i change the preset, it speaks the infamous "bank open failure".

I'm using a Panasonic Li-On 3200mAh protected battery. One thing i noticed is, that Voltage level in serial monitor is changing from aprox 3.50V - 3.70V. I added 100kohm resistor and changed the valie of pullup resistor to "100000". Blade recognision resistor is valued to 56ohm, but i leave it to default value of 7800ohm (default). Number of blades is set to "1".

Any solutions?

Offline miib123

  • No Force
  • *
  • Posts: 20
  • Um...Hello?
Re: TeensySaber Software Discussion
« Reply #284 on: February 09, 2018, 07:32:01 AM »

 

retrousse