Announcement

Collapse
No announcement yet.

Playing Sounds or Tones for debugging?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Playing Sounds or Tones for debugging?

    Telemetry is nice, but often it's hard to focus on both the bot and the driver phone. We used to make use of the many tones to troubleshoot. Is there an easy way to play sounds on the robot controller phone? (or drive station I suppose) Thanks for the pointers.

  • #2
    Originally posted by korimako View Post
    Telemetry is nice, but often it's hard to focus on both the bot and the driver phone. We used to make use of the many tones to troubleshoot. Is there an easy way to play sounds on the robot controller phone? (or drive station I suppose) Thanks for the pointers.
    You can certainly write code to play sound on the RC phone but since FIRST does not release the code for the DS phone, you can't modify it to add sound to it.

    Comment


    • #3
      Here's what I did to use sounds to debug my auto code...

      created a "Raw" folder in the Resources (Res) section of the project.

      Copied a beep.wav file into the Raw Folder

      In the Opmode.. declare some variables

      // Sound variables
      public SoundPool mySound;
      public int beepID;


      In the init() method: setup the sounds

      mySound = new SoundPool(1, AudioManager.STREAM_MUSIC, 0); // PSM
      beepID = mySound.load(hardwareMap.appContext, R.raw.beep, 1); // PSM


      To beep

      mySound.play(beepID,1,1,1,0,1);

      Phil.

      Comment


      • #4
        Can you update these instructions?

        Originally posted by Philbot View Post
        Here's what I did to use sounds to debug my auto code...

        created a "Raw" folder in the Resources (Res) section of the project.

        Copied a beep.wav file into the Raw Folder

        In the Opmode.. declare some variables

        // Sound variables
        public SoundPool mySound;
        public int beepID;


        In the init() method: setup the sounds

        mySound = new SoundPool(1, AudioManager.STREAM_MUSIC, 0); // PSM
        beepID = mySound.load(hardwareMap.appContext, R.raw.beep, 1); // PSM


        To beep

        mySound.play(beepID,1,1,1,0,1);

        Phil.
        We used these instructions with success earlier in the summer. However we have since obtained a new computer and have loaded the current version of Android studio. Now it will not recognize the "R" in the code. I'll be perfectly honest, I'm not a coder and I've tried the few tricks i know to make this work to no avail. We would really like to get this going again by next week when we have our first fundraiser of the season.

        Thanks for the help!
        Cody

        Comment


        • #5
          Hi

          I'll check it out with 2.0, but if you're like me, when you copied this project, you may have forgotten to copy the "raw" folder underneath the res folder.

          Since there is no folder, it can't resolve R.raw

          Phil.

          Comment


          • #6
            We used to have a sound module in our library when FTC was using the Mindstorms. When switching to Android, since the hardware is different, we did not port the sound module over. But eventually, we do want to have the capability of playing a tone with a given frequency and duration. The time is finally here. We just ported that module over to Android. You can see it here.
            https://github.com/trc492/FtcSampleC.../FtcSound.java
            To demonstrate how this is used, we have written the FtcTestSong opmode that calls another new module FtcSongPlayer that will play two songs on the RobotController phone.
            https://github.com/trc492/FtcSampleC...cTestSong.java
            https://github.com/trc492/FtcSampleC...ldThumper.java
            We also added code to the FtcTestWildThumper opmode that allows a song playing in the background while driving the robot around. This demonstrates multitasking (i.e. operating the robot should not affect the background song playing).

            Comment


            • #7
              Use CDIM for debugging

              Originally posted by korimako View Post
              Telemetry is nice, but often it's hard to focus on both the bot and the driver phone. We used to make use of the many tones to troubleshoot. Is there an easy way to play sounds on the robot controller phone? (or drive station I suppose) Thanks for the pointers.
              Turning LEDs on/off on the robot may be better for debugging than playing sounds, particularly in noisy environments. The Core Device Interface Module (CDIM) has two built-in LEDs, one red and one blue, that your opmodes can turn on/off, or blink at various intervals. I believe you can also control up to 8 additional LEDs per CDIM via the Digital Output ports. The latter method allows you to place different color LEDs at strategic spots on the robot.

              Of course, there are other possibilities with the CDIM, like interfacing to a home-grown debug monitor via I2C, Analog Output, or Digital Output. A home-grown debug monitor is probably not legal for robot competition, but useful for development, and useful for the judging competition.

              Comment


              • #8
                Originally posted by mikets View Post
                We used to have a sound module in our library when FTC was using the Mindstorms. When switching to Android, since the hardware is different, we did not port the sound module over. But eventually, we do want to have the capability of playing a tone with a given frequency and duration. The time is finally here. We just ported that module over to Android. You can see it here.
                https://github.com/trc492/FtcSampleC.../FtcSound.java
                To demonstrate how this is used, we have written the FtcTestSong opmode that calls another new module FtcSongPlayer that will play two songs on the RobotController phone.
                https://github.com/trc492/FtcSampleC...cTestSong.java
                https://github.com/trc492/FtcSampleC...ldThumper.java
                We also added code to the FtcTestWildThumper opmode that allows a song playing in the background while driving the robot around. This demonstrates multitasking (i.e. operating the robot should not affect the background song playing).
                BTW, I wasn't clear on my previous post and in the examples. You don't need to play a song to make sound. If you just want a simple tone you can just import FtcSound and call the playTone method. playTone takes a frequency and duration as parameters.

                Comment


                • #9
                  I have added the FtcSound example in the WildThumper code. You can now press the B button on the gamepad to hear a 440 Hz tone for 0.2 seconds and release the B button to hear a 880 Hz tone for 0.2 second.

                  Comment


                  • #10
                    Thank GearTicks for posting the link to the spec sheet of the CDIM on another thread. After reading it, I realized the AnalogOutput ports can be used as tone generators. They can be programmed to generate sine/square/triangle wave with specified frequency. We now have updated our sound module to support this hardware. We have also ordered a few Piezoelectric speakers from amazon. In theory, if we plug that to one of the AnalogOutput ports, we should be able to make tones with it. I will post some pictures when that arrives and tests successfully. In addition, we found our waveform generation code produced clicking sound when playing a song. This is caused by the abrupt transition between one tone to the next. Because of this, we have now added support to apply a sound envelope (ADSR) to the generated waveform. This allows the user to define a sound envelope that will smooth the transition between notes.

                    Comment


                    • #11
                      Originally posted by mikets View Post
                      Thank GearTicks for posting the link to the spec sheet of the CDIM on another thread. After reading it, I realized the AnalogOutput ports can be used as tone generators. They can be programmed to generate sine/square/triangle wave with specified frequency. We now have updated our sound module to support this hardware. We have also ordered a few Piezoelectric speakers from amazon. In theory, if we plug that to one of the AnalogOutput ports, we should be able to make tones with it. I will post some pictures when that arrives and tests successfully. In addition, we found our waveform generation code produced clicking sound when playing a song. This is caused by the abrupt transition between one tone to the next. Because of this, we have now added support to apply a sound envelope (ADSR) to the generated waveform. This allows the user to define a sound envelope that will smooth the transition between notes.
                      Does anybody have experience programming the AnalogOutput ports? I got the piezoelectric speakers in and hooked it up to the Analog output port but no sound was generated. Then I put an oscilloscope on the pins and saw nothing. Then I changed the code to use voltage mode instead of sine wave mode and just changing the voltage from +4V to -4V every time I play the next tone. I saw the voltage changing on the scope. So voltage mode was okay. But changing it back to sine wave mode or triangle wave mode, nothing! Basically, every time I play a note I did the following:
                      Code:
                      analogOut.setAnalogOutputMode(outputMode);
                      analogOut.setAnalogOutputFrequency((int)frequency);
                      where outputMode was either 1 (sine) or 3 (triangle) and of course the frequency varies (e.g. 440). Then I set a timer for the duration and turns it off when expired. Anything I missed here?

                      Comment


                      • #12
                        Originally posted by mikets View Post
                        Does anybody have experience programming the AnalogOutput ports? I got the piezoelectric speakers in and hooked it up to the Analog output port but no sound was generated. Then I put an oscilloscope on the pins and saw nothing. Then I changed the code to use voltage mode instead of sine wave mode and just changing the voltage from +4V to -4V every time I play the next tone. I saw the voltage changing on the scope. So voltage mode was okay. But changing it back to sine wave mode or triangle wave mode, nothing! Basically, every time I play a note I did the following:
                        Code:
                        analogOut.setAnalogOutputMode(outputMode);
                        analogOut.setAnalogOutputFrequency((int)frequency);
                        where outputMode was either 1 (sine) or 3 (triangle) and of course the frequency varies (e.g. 440). Then I set a timer for the duration and turns it off when expired. Anything I missed here?
                        Never mind, I got it all working now. Technically, it is not quite working yet but it's because of the speaker I ordered. I got it working on the oscilloscope. I got a waveform from the Analog output port pin. I am ordering different speakers and will test it when it arrives.
                        The working code is here: https://github.com/trc492/FtcSampleC...b/FtcTone.java

                        Comment


                        • #13
                          Originally posted by mikets View Post
                          Never mind, I got it all working now. Technically, it is not quite working yet but it's because of the speaker I ordered. I got it working on the oscilloscope. I got a waveform from the Analog output port pin. I am ordering different speakers and will test it when it arrives.
                          The working code is here: https://github.com/trc492/FtcSampleC...b/FtcTone.java
                          Just did some cleanup of the code and renamed some of the classes to make it more readable. Here are the new names of the classes:
                          - FtcAndroidTone: This is a platform dependent tone generator that uses Android AudioTrack.
                          - FtcAnalogOutTone: This is a platform dependent tone generator that uses the Core Device Interface Module AnalogOut ports.
                          - TrcTone: This is the platform independent tone generator that is inherited by all platform dependent tone generators.
                          - TrcSongPlayer: This is a platform independent song player that uses one of the platform dependent tone generators.
                          - FtcTestSong: This is a demo on how to play a song using the TrcSongPlayer class.
                          - FtcTeleOpWildThumper: This is a demo on how to integrate song player and tone generator into a robot OpMode.

                          Comment


                          • #14
                            Anybody has a pointer to the data sheet of the Core Device Interface Module? In particular, I need to know the max output current of the analog output port. I got the speaker kind of working (https://smile.amazon.com/Arduino-Com..._cd_al_qh_dp_i) except the volume is extremely low. I can barely hear it when putting my ear up against it. I may have to design an amplifier for it but without the data sheet for both the speaker and the CDIM, it would be a trial and error affair. Anybody knows about this speaker and the CDIM and the proper way to drive them?
                            BTW, the updated link to the sources are:
                            - FtcAndroidTone: https://github.com/trc492/FtcSampleC...droidTone.java
                            - FtcAnalogOutTone: https://github.com/trc492/FtcSampleC...ogOutTone.java
                            - TrcTone: https://github.com/trc492/FtcSampleC...b/TrcTone.java
                            - TrcSongPlayer: https://github.com/trc492/FtcSampleC...ongPlayer.java
                            - FtcTestSong: https://github.com/trc492/FtcSampleC...cTestSong.java
                            - FtcTeleOpWildThumper: https://github.com/trc492/FtcSampleC...ldThumper.java

                            Comment


                            • #15
                              Analog output port
                              -4 –+4 volts at 1mA

                              from:
                              http://modernroboticsinc.com/core-de...rface-module-2

                              Comment

                              Working...
                              X