Shop OBEX P1 Docs P2 Docs Learn Events
Unable to play music while the Activity Bot Roaming(Solved by Andy Lindsey) — Parallax Forums

Unable to play music while the Activity Bot Roaming(Solved by Andy Lindsey)

msiriwardenamsiriwardena Posts: 301
edited 2019-04-05 20:07 in Learn with BlocklyProp
The activity Bot with XBee S2C is programmed to roam and it works.
I am trying to play music while roaming.

I have placed the wav blocks in many places in the program and no music
and most of the time the bot does no move.
Since the wav block "Play file" starts 2 new cogs, should play music.
I can play music using the wav blocks and not while roaming.
I saw the "Whitt's" video in it the " voice turning Etc. " stops when
the robot moves.
I want the bot to play music and roam at the same time.

I have placed the program in the public projects - Named:"XBee S2C RF controlled Receiver Activity Bot"
I will place the "XBeeX2C Transmitter activity Bot" in the public projects.

I would like some advice,

Thank you,

Siri
«1

Comments

  • I have also attached screen shot of the Transmitter and receiver programs.

    Siri
    1920 x 1080 - 220K
    1920 x 1080 - 305K
  • Can you post the full program including the wav playing part?

    Have you tried "Download SimpleIde Files" and reviewing the C program to see how the wav code is being used? I find that a good way to debug placement of blocks or calling functions.

    Tom
  • msiriwardenamsiriwardena Posts: 301
    edited 2019-03-17 19:06
    @twm47099

    I added the wav blocks to many places in the program.

    Attached is the program with wav blocks. I even tried adding a "empty Frever" block.

    Thanks for your help.

    Siri
    1920 x 1080 - 325K
  • msiriwardenamsiriwardena Posts: 301
    edited 2019-03-17 21:53
    I found by trying to play music on the activity bot you need
    2 wav blocks and pause. 1.set volume and play file wave blocks
    and a pause placed anywhere in the screen.- see screen shot.

    I do not know whether it is by design or not.
    If you delete the pause, music will not play.

    The problem begins when you add this set up to your program.

    Siri

    PS: I found out ,it plays music and bot roaming without navigation.
    The bot just goes straight a head. No fun.

    siri
    1920 x 1080 - 131K
  • twm47099twm47099 Posts: 867
    edited 2019-03-18 03:18
    Can you make the XBEE controlled receiver a public project, or click on the download SimpleIDE Files in the dropdown on the top right side. I want to see where the wav call is located in relation to the rest of the code.

    Looking at the blocks you posted I think that the initial cog is calling the wav function which then requires the pause to play the wav. No other commands can happen in the cog until the pause finishes.

    Try defining the wav as a function in a new cog like in the image below. Even though wav opens new cogs, you will have to call it in a new cog so that the original can keep doing other stuff. The problem will be if you run out of cogs (XBEE, abot commands, wav cogs, etc.) I think you will probably use 6 cogs.

    Hope this works (I don't have the hardware to try it out at this time).
    Tom

    blocks.pngblocks.png
    1280 x 720 - 161K
  • Let's make sure you're not running out of processors.* Read this and count your usage http://learn.parallax.com/support/reference/propeller-blocklyprop-block-reference/about-multicore

    *In BlocklyProp, we refer to the extra processors as processors, but in Spin/ASM we call them cogs.

    Ken Gracey

  • @twm47099 ,@KenGracey

    The project has a public link "XBee RF controlled Receiver Activity Bot"
    and tried what you suggested and no music or any movement from the
    bot and XBee is receiving the transmitted signals "The blue LED blinks"
    but no response.
    The IDE files are attached.

    Ken - As I counted the number of "cogs - I am little more verse with spin"
    The number comes to 5/6 the most.

    Thanks for the help.

    Siri
  • @msiriwardena

    In "main" try putting an infinite loop after
    cog_run(receiver, 128);
      drive_speed(64, 64);
    
    I think that the way it is currently written, "main" starts the other cogs, but then the program ends. Keep it running with a repeat forever block.

    Tom

  • @twm47099

    I placed an empty " forever block" at end after "drive_speed(64,64)" and
    no music or any movement from the bot.

    Siri
  • Hi Siri,

    Could you please post a link to your project? I found one that has a similar name, but it doesn't look like what you have been talking about above.

    In the meantime, I took a look at the zipped C code, and noticed that it is launching the dowav function into a new processor. That could be one of the causes of the unusual behavior. When your code plays a wav file, it automatically lunches another processor, and then the wav code runs in the background while your main code can move on. When you try to do that from another processor, the block does not allocate enough stack space for the wav player. Even if it could, I'm pretty sure the memory penalty would also cause trouble.

    Andy

  • Hi Siri,

    Could you please post a link to your project? I found one that has a similar name, but it doesn't look like what you have been talking about above.

    In the meantime, I took a look at the zipped C code, and noticed that it is launching the dowav function into a new processor. That could be one of the causes of the unusual behavior. When your code plays a wav file, it automatically lunches another processor, and then the wav code runs in the background while your main code can move on. When you try to do that from another processor, the block does not allocate enough stack space for the wav player. Even if it could, I'm pretty sure the memory penalty would also cause trouble.

    Andy

    I've had this exact type of failure, too. Please see this code as an example http://learn.parallax.com/tutorials/language/blocklyprop/spooky-doll-project/adding-sound-and-movement, Siri. When creating this project I also tried to put the wav file playback in a New Processor block, which does not work.

    Ken Gracey
  • Hi Siri,

    Could you please post a link to your project? I found one that has a similar name, but it doesn't look like what you have been talking about above.

    In the meantime, I took a look at the zipped C code, and noticed that it is launching the dowav function into a new processor. That could be one of the causes of the unusual behavior. When your code plays a wav file, it automatically lunches another processor, and then the wav code runs in the background while your main code can move on. When you try to do that from another processor, the block does not allocate enough stack space for the wav player. Even if it could, I'm pretty sure the memory penalty would also cause trouble.

    Andy

    Andy,
    Will the ActivityBot be able to accept commands from the XBEE and change movement (moving continuously) while the wav is playing?

    Thanks
    Tom
  • @"Andy Lindsay (Parallax)" ,@KenGracey

    I tried without using a new processor and nothing happens.

    @twm47099 - The activity bot receives the commands(blue LED flickers) but robot will
    not react to the commands.

    The attached code(IDE) will only play music for ashort while(due to the pause in wavefunction)


    siri
  • edited 2019-03-19 00:25
    For now, I'll make suggestions with respect to the C code.

    P.S. BlocklyProp examples with equivalent code in next post.

    If you prefer BlocklyProp advice, you can make the project public. and share the link. To do this, in your project, click the menu in the upper-right below the project name and select Edit Project Details. Click the Public button, and then click Save.

    I recommend combining in small pieces. As in, test each of these individually first, and then combine them.

    For example, this would test to make sure the WAV file plays.
    // Test WAV play.c
    
    #include "simpletools.h"
    #include "wavplayer.h"
    
    int main()
    {
      sd_mount(22, 23, 24, 25);
      wav_play("loveher.wav");
      pause(5000);
      wav_stop();
    }
    

    ...and this would test a simple ActivityBot maneuver.
    // Test ActivityBot forward
    
    #include "simpletools.h"
    #include "abdrive360.h"
    
    int main()
    {
      drive_speed(32, 32);
      pause(5000);
      drive_speed(0, 0);
    }
    

    Next, you can try them together, like this:
    // Test WAV Play with ActivityBot forward.c 
    
    #include "simpletools.h"
    #include "abdrive360.h"
    #include "wavplayer.h"
    
    int main()
    {
      drive_speed(32, 32);
      sd_mount(22, 23, 24, 25);
      wav_play("loveher.wav");
      pause(5000);
      drive_speed(0, 0);
      wav_stop();
    }
    

    Other things to try in the C code you posted:

    On line 28 of the C code, try adding while(1);

    Try adding drive_speed(0, 0); as the very first call in the main function.
  • edited 2019-03-19 00:52
    BlocklyProp versions of small tests:
    Here are BlocklyProp examples of the same tests:
    Make sure to check the comments in Test WAV Play with ActivityBot Forward.
  • edited 2019-03-19 00:52
    Here is one more, with XBee added. Make sure to check the note in comments by the XBee repeat loop.
    Test Wav Play with ActivityBot Forward add XBee
  • In the c file you posted
    xbee = fdserial_open(9,8,0,9600);
    
    is in main() (in the blocks image it is in the receive function?)

    One thing I would suggest trying in C is moving that line out of main and putting it as the first line of receiver(). I've written a few programs using a bluetooth receiver in its own cog and always did the fdserial_open in the bluetooth cog.
  • @ twm47099,
    I altered the program as you suggested putting
    the initialization of the Xbee in the Receiver function.

    The program only played the whole song and
    will not react to any Xbee commands from the transmitter.

    Siri
  • @"Andy Lindsay (Parallax)"
    I made public link to the project as you suggested'

    I will try the other suggestions a little later
    and let you know the results.

    Thanks for helping me.

    Siri
  • Thank you Siri.

    All I see that's public under your name is this one:

    http://blockly.parallax.com/blockly/editor/blocklyc.jsp?project=87887

    The one I think I should be looking at is this:

    http://blockly.parallax.com/blockly/editor/blocklyc.jsp?project=84127

    Is that the correct project? If so, it is still not shared.
  • msiriwardenamsiriwardena Posts: 301
    edited 2019-03-19 18:39
    @"Andy Lindsay (Parallax)"

    The project #84127 is mine.

    I will try sharing again.

    Siri
    PS :http://blockly.parallax.com/blockly/projectlink?id=84127&key=c4bf128b-c5dd-4ec8-99d5-a73376f66847 - this the link.
    I have taken the WAV blocks off .The project as is (with out -wav is responding to XBee commands from the Transmitter.
    Exactly as I wanted.
    Siri
  • @"Andy Lindsay (Parallax)"
    When I play the C file to test the wav player, error pop up
    "unable to connect to port"

    But when I play the Blocks :1.wav.volume(10)
    2.wav play file(loveher)
    3.pause(90000)
    The full song is plays.

    Siri

    ps; I will try your C file few more times.
  • msiriwardenamsiriwardena Posts: 301
    edited 2019-03-19 19:16
    @"Andy Lindsay (Parallax)" ,

    After I added the Line after mount "wav_volume(10)"
    The song played.

    So test wav passed.
    Tested maneuver it passed too.
    Maneuver and sound both together - passed too

    Siri
  • Okay, thanks for the updates. The WAV library has had a number of updates recently. There used to be a default volume in the 7 neighborhood. I'll take a look.
  • msiriwardenamsiriwardena Posts: 301
    edited 2019-03-19 20:00
    @"Andy Lindsay (Parallax)"

    when I add "while(1);" 28th line in C code and when drive_speed(0, 0) - nothing happens.

    Regards,
    Siri
  • @"Andy Lindsay (Parallax)" ,@KenGracey,@twm47099

    I have placed the Function "dowave" at all the positions in the program:
    1.At the beginning before initializing the Activity bo
    2.After initializing activity bot
    3.Before and after the "function receiver"
    4.Placed it even in the "receiver function"
    As far as I can see no matter where I place the "do wav " nothing happens.
    will not play music or bot responds to transmitted commands.

    I don't know whether the observation that when the "do wav" function in the
    "function receiver" RED LED glows on the XBee.

    Other observation is that Robot moves and play music without the Xbee.

    I am out of any ideas.

    I hope you will find a solution.

    Thank you.

    Siri

  • edited 2019-03-20 00:41
    WAV Player and ActivityBot work together, but when I add XBee communication, the program gets too large. You do not see a compiler error because it's not too large to run, but there is some memory that gets dynamically allocated, and as a result, the app stops responding.

    I am writing a version of the test code that receives XBee values without using the simplextext library's dprint function. If that works, there might be enough room for all to work together.
  • edited 2019-03-20 00:39
    Okay, here is a test application where you set the speeds of the ActivityBot wheels and the play state of the WAV player.

    IMPORTANT: I may have inadvertently changed the wiring. Or not, please check your boards. On my ActivityBot (receiver) and my Activity Board connected to the computer (transmitter), both have P9 connected to DO and P8 connected to DI.

    Load Receiver XBee WAV ActivityBot.c into your ActivityBot and set PWR to 2. (Don't worry if nothing happens.)
    Connect the transmitting Activity Board to the computer and run Transmitter to XBee WAV ActivityBot.c. Then, follow the prompts in the terminal. You will enter left speed, right speed, and play state. When you press Enter after that third value, the ActivityBot should set wheel speeds and play the tune.

    ActivityBot Code (Receiver)
    // Receiver XBee WAV ActivityBot.c
    
    #include "simpletools.h"
    #include "abdrive360.h"
    #include "wavplayer.h"
    #include "fdserial.h"
    
    #define VAL_ELEMENTS 3
    void xbee_lite(void *par);
    
    fdserial *xbee;
    
    char startChar = '!';
    volatile int val[VAL_ELEMENTS] = {0, 0, 0};
    unsigned int stack[40 + 25];
    
    int main() 
    {
      sd_mount(22, 23, 24, 25);
      xbee = fdserial_open(9, 8, 0, 9600);
      cogstart(xbee_lite, NULL, stack, sizeof(stack));
      pause(5000);
      while (1) 
      {
        pause(50);
        drive_speed(val[0], val[1]);
        if(val[2] == 1)
        {
          if(!wav_playing())
          {
            wav_play("loveher.wav");
          }
        }      
        else if(val[2] == 0)
        {
          if(wav_playing())
          {
            wav_stop();
          }        
        }      
      }
    }
    
    void xbee_lite(void *par)
    {
      while(1)
      {
        while(fdserial_rxChar(xbee) != startChar);
        int v = 0;
        int sign = 1;
        int idx = 0;
        while(1)
        {
          if(fdserial_rxReady(xbee))
          {
            char c = fdserial_rxChar(xbee);
            if(c == startChar) break;
            if((c >= '0' && c <= '9') || (c == '-'))
            {
              if(c == '-') sign = -1;
              else
              {
                v *= 10;
                v = v + (c - '0');
              }            
            }
            else
            {
              v = v * sign;
              val[idx] = v;
              v = 0;
              sign = 1;
              idx++;
            }
            if(idx >= VAL_ELEMENTS) break;
          }
        }    
      }
    }
    

    Code for Activity Board Connected to Computer (Transmitter)
    // Transmetter to XBee WAV ActivityBot.c
    
    #include "simpletools.h"
    #include "fdserial.h"
    
    #define VAL_ELEMENTS 3
    
    fdserial *xbee;
    
    int item;
    char startChar = '!';
    int val[VAL_ELEMENTS] = {0, 0, 0};
    
    int main() 
    {
      print("Speed ranges are -128 to 128.\r");
      print("Press Enter key after each value.\r\r");
      
      xbee = fdserial_open(9, 8, 0, 9600);
      while(1)
      {
        print("Enter left speed: ");
        scan("%d", &val[0]);
        print("Enter right speed: ");
        scan("%d", &val[1]);
        print("Enter 1 to play or 0 to stop: ");
        scan("%d", &val[2]);
        print("You entered %d, %d, %d\r\r", val[0], val[1], val[2]);
        dprint(xbee, "!%d %d %d\r", val[0], val[1], val[2]);
      }    
    }
    
  • @"Andy Lindsay (Parallax)"
    Your code works but it defeat my goal to
    have a mobile transmitter not attached to the computer.

    I sincerely thank you effort to solve my issue.

    Siri
  • edited 2019-03-20 16:50
    The C code above was a test of solving the most difficult hurdle, which was XBee + WAV + ActivityBot 360. The solution was to write a custom function that takes less memory than the libraries we normally use for XBees.

    Next step is converting it to something you can continue to work with. To that end, do you prefer to develop this in BlocklyProp or C?
Sign In or Register to comment.