Question on macro script

4 posts / 0 new
Last post
Santa Matt
Santa Matt's picture
Question on macro script

OK, this is going to be a long one. I have been working on a rather large macro containing multiple scripts. There is a master scriipt that is controlled by pressing the various buttons on the RS Media. Originally I was using the basic system variable/function IE. "if [ $(RSM_GAUNTLET_R_O) -eq "1" ]; then" But this takes a long time to scan through all of the buttons. Helibot shared some of his vast knowledge and showed me a lower level way to access the buttons. So I have this script:

echo "1" > /tmp/state/scriptrun
/usr/bin/robot/pipe /tmp/robot_pipe 9 2 0 0 0
# Master Control
/usr/bin/robot/scripts/clear_screen.sh
/usr/bin/robot/scripts/display_image.sh ./Menu.jpg 0 &
FootRF=`/usr/bin/robot/read_confile.dat /tmp/state/RSM_FOOT_R_F_VAR`
echo -e "\033[0;31;40m1 FootRF = $FootRF\033[0;37;40m\033[39m"
while [ $FootRF <> 1 ]; do
      Hand=`/usr/bin/robot/read_confile.dat /tmp/state/RSM_GAUNTLET_R_O_VAR`
      echo -e "\033[0;31;40m1 Hand = $Hand\033[0;37;40m\033[39m"
      if [ $Hand = 1 ]; then
            /usr/bin/robot/scripts/clear_screen.sh
            #cd /mnt/sd/Personalities/Sparky/Macros/CONANIM03
        echo -e "\033[0;31;40mCalling Desktop companion\033[0;37;40m\033[39m"
            ./deskcomp.sh
      fi
      Hand=`/usr/bin/robot/read_confile.dat /tmp/state/RSM_GAUNTLET_R_I_VAR`
      echo -e "\033[0;31;40m2 Hand = $Hand\033[0;37;40m\033[39m"
      if [ $Hand = 1 ]; then
            /usr/bin/robot/scripts/clear_screen.sh
            #cd /mnt/sd/Personalities/Sparky/Macros/CONANIM04
        echo -e "\033[0;31;40mCalling Robo DJ\033[0;37;40m\033[39m"
            ./RoboDJ.sh
      fi
      Hand=`/usr/bin/robot/read_confile.dat /tmp/state/RSM_GAUNTLET_L_I_VAR`
      echo -e "\033[0;31;40m3 Hand = $Hand\033[0;37;40m\033[39m"
      if [ $Hand = 1 ]; then
            /usr/bin/robot/scripts/clear_screen.sh
            #cd cd /mnt/sd/Personalities/Sparky/Macros/CONANIM05
        echo -e "\033[0;31;40mCalling rules\033[0;37;40m\033[39m"
            ./Rules.sh
      fi
      Hand=`/usr/bin/robot/read_confile.dat /tmp/state/RSM_GAUNTLET_L_O_VAR`
      echo -e "\033[0;31;40m4 Hand = $Hand\033[0;37;40m\033[39m"
      if [ $Hand = 1 ]; then
            /usr/bin/robot/scripts/clear_screen.sh
            #cd /mnt/sd/Personalities/Sparky/Macros/CONANIM06
            ./Clock.sh
      fi
      FootRF=`/usr/bin/robot/read_confile.dat /tmp/state/RSM_FOOT_R_F_VAR`
      echo -e "\033[0;31;40m2 FootRF = $FootRF\033[0;37;40m\033[39m"
done
echo -e "\033[0;31;40m3 FootRF = $FootRF\033[0;37;40m\033[39m"
/usr/bin/robot/scripts/play_audio.sh /mnt/sd/Personalities/Sparky/Sounds/STOP01.mp3 0 0 &
/usr/bin/robot/pipe /tmp/robot_pipe 9 2 1 0 0
echo "0" > /tmp/state/scriptrun
exit 0

I have added echo statements so I can track the action of the script. I call it with the  USB terminal and everything proceeds as expected and it is lightening fast. Only one problem, it never recognizes a button press.

If I launch it with the remote it stops imediately. 

If I run it via the USB terminal without the echo statements I get an error about something being read only?!?

I am flat out of ideas. I don't know why it doesn't work and I don't know why it acts differently in different situations. Any and all suggestions welcome.

 

Helibot
Helibot's picture

Hey Matt,

   I missed this post of yours until now (you should have sent me a PM :-) ).....I had alook at it tonight and finially figured out the issues.
  1) The xxx_VAR files do NOT get updated after you send "/usr/bin/robot/pipe /robot_pipe 9 2 0 0 0
". Not sure why this is, but it is definitely the cause of why the buttons are not detected. Instead try "/usr/bin/robot/pipe /tmp/robot_pipe -2 1 0 0 0" (I used this command in the RSMMediaClock. I know it stops the robot going to sleep after 2 minutes, not sure what else it limits? If your other scripts change in behaviour then let me know and we can discuss it further.)

2) When a button is pressed the xxx_VAR files is set to 1. When the button is released the files does NOT get set to 0.  Therefore you need to clear the values from the xxx_VAR files after you detect the 1. (You probably should also clear them all at the start of your script (or buttons that have previously been pressed will trigger actions immediately). Clear the xxx_VAR files by the command '/usr/bin/robot/write_confile.dat /tmp/state/xxx_VAR 0'

3) In your while loop you used [ $FootRF <> 1  ]. I think it should be [ $FootRF != 1 ].  I think the '<>' may have been seen as redirect commands, which is why you may have got the error about readonly and also maybe why it stopped immediately when run from the remote?. 

So try the version below. It ran OK for me (from the serial console command line) -  it enters the loop , checks for key presses every 2 secs , runs the right scripts for each button and exits when Right Foot Front button is pressed.

echo "1" > /tmp/state/scriptrun
#/usr/bin/robot/pipe /tmp/robot_pipe 9 2 0 0 0
/usr/bin/robot/pipe /tmp/robot_pipe -2 1 0 0 0

/usr/bin/robot/write_confile.dat /tmp/state/RSM_FOOT_R_F_VAR 0
/usr/bin/robot/write_confile.dat /tmp/state/RSM_FOOT_L_F_VAR 0
/usr/bin/robot/write_confile.dat /tmp/state/RSM_GAUNTLET_R_I_VAR 0
/usr/bin/robot/write_confile.dat /tmp/state/RSM_GAUNTLET_R_O_VAR 0
/usr/bin/robot/write_confile.dat /tmp/state/RSM_GAUNTLET_L_I_VAR 0
/usr/bin/robot/write_confile.dat /tmp/state/RSM_GAUNTLET_L_O_VAR 0
echo Cleared state files

# Master Control
/usr/bin/robot/scripts/clear_screen.sh
/usr/bin/robot/scripts/display_image.sh ./Menu.jpg 0 &
FootRF=`/usr/bin/robot/read_confile.dat /tmp/state/RSM_FOOT_R_F_VAR`
echo -e "FootRF = $FootRF"
while [ $FootRF != 1 ]; do
      Hand=`/usr/bin/robot/read_confile.dat /tmp/state/RSM_GAUNTLET_R_O_VAR`
      echo -e "Hand = $Hand"
      if [ $Hand = 1 ]; then
            /usr/bin/robot/write_confile.dat /tmp/state/RSM_GAUNTLET_R_O_VAR 0
            /usr/bin/robot/scripts/clear_screen.sh
            #cd /mnt/sd/Personalities/Sparky/Macros/CONANIM03
        echo -e "Calling Desktop companion"
            ./deskcomp.sh
      fi
      Hand=`/usr/bin/robot/read_confile.dat /tmp/state/RSM_GAUNTLET_R_I_VAR`
      echo -e "Hand = $Hand"
      if [ $Hand = 1 ]; then
            /usr/bin/robot/write_confile.dat /tmp/state/RSM_GAUNTLET_R_I_VAR 0
            /usr/bin/robot/scripts/clear_screen.sh
            #cd /mnt/sd/Personalities/Sparky/Macros/CONANIM04
        echo -e "Calling Robo DJ"
            ./RoboDJ.sh
      fi
      Hand=`/usr/bin/robot/read_confile.dat /tmp/state/RSM_GAUNTLET_L_I_VAR`
      echo -e "Hand = $Hand"
      if [ $Hand = 1 ]; then
            /usr/bin/robot/write_confile.dat /tmp/state/RSM_GAUNTLET_L_I_VAR 0
            /usr/bin/robot/scripts/clear_screen.sh
            #cd cd /mnt/sd/Personalities/Sparky/Macros/CONANIM05
        echo -e "Calling rules"
            ./Rules.sh
      fi
      Hand=`/usr/bin/robot/read_confile.dat /tmp/state/RSM_GAUNTLET_L_O_VAR`
      echo -e "Hand = $Hand"
      if [ $Hand = 1 ]; then
            /usr/bin/robot/write_confile.dat /tmp/state/RSM_GAUNTLET_L_O_VAR 0
            /usr/bin/robot/scripts/clear_screen.sh
            #cd /mnt/sd/Personalities/Sparky/Macros/CONANIM06
            ./Clock.sh
      fi
      echo Sleeping....
      /usr/bin/robot/sleep 2000

      FootRF=`/usr/bin/robot/read_confile.dat /tmp/state/RSM_FOOT_R_F_VAR`
      echo -e "FootRF = $FootRF"
done
echo -e "FootRF = $FootRF"
/usr/bin/robot/scripts/play_audio.sh /mnt/sd/Personalities/Sparky/Sounds/STOP01.mp3 0 0 &
#/usr/bin/robot/pipe /tmp/robot_pipe 9 2 1 0 0
/usr/bin/robot/pipe /tmp/robot_pipe -2 1 1 0 0
echo "0" > /tmp/state/scriptrun

A few last comments :-
-I added a sleep to the loop, so it only checks the buttons every two secs, not sure if this is necessary, but it should stop the script hogging all the processor time by sitting in the while loop. 
-If multiple buttons are pressed (within the two seconds) then multiple if...fi  statements could be triggered (ie two of your scripts maybe run at the same time?). So changing to a if...elif..elif..fi construct maybe better.
-If any of the other scripts you are calling contain '/usr/bin/robot/pipe /tmp/robot_pipe 9 2 0 0 0' then your master script will not detect any more keys until the '/usr/bin/robot/pipe /tmp/robot_pipe 9 2 1 0 0' command is sent. Most scripts that send 9 2 0 0 0 also send the 9 2 1 0 0 at the end, so it will probably be OK!!

Good luck and Cheers
    Helibot

Santa Matt
Santa Matt's picture

Helibot said:
A few last comments :-
-I added a sleep to the loop, so it only checks the buttons every two secs, not sure if this is necessary, but it should stop the script hogging all the processor time by sitting in the while loop. 
-If multiple buttons are pressed (within the two seconds) then multiple if...fi  statements could be triggered (ie two of your scripts maybe run at the same time?). So changing to a if...elif..elif..fi construct maybe better.
-If any of the other scripts you are calling contain '/usr/bin/robot/pipe /tmp/robot_pipe 9 2 0 0 0' then your master script will not detect any more keys until the '/usr/bin/robot/pipe /tmp/robot_pipe 9 2 1 0 0' command is sent. Most scripts that send 9 2 0 0 0 also send the 9 2 1 0 0 at the end, so it will probably be OK!!
Good luck and Cheers
    Helibot

OK, I tried your script and it does read the buttons OK, and quickly but, it stops everything else. I tried rearranging some of the robot/pipe commands but to no avail. how did you figure out the parameters for the robot/pipe command? I think that is definitly the answer but it still needs some tweeking.

 

Also I put it in this forum so others smarter than me could use what we figure out and progress the state of RS Media programming another step. Sometimes it is easier to send a private message or an Email, especially if also sending a file or group of files. But a script I figured we could post for all to see. :) Next time I will also send you a tickler to stuff I post public about stuff we're discussing.

Helibot
Helibot's picture

Hi Sanata Matt,
   The "/usr/bin/robot/pipe /tmp/robot_pipe -2 1 0 0 0" is from one of the other scripts. (I think it was from the play_video.sh script.)
I dont understand the actual paramaters :-(.   It seems that depending on the paramaters it tells the RSMedia programs running on the Linux processor & the Robot board to behave differently.
Below are some extracts from my notes file - they show different paramaters from a variety of 'action scripts' from RSMedia.

This is wrapped around all bodycon scripts
/usr/bin/robot/pipe /tmp/robot_pipe 9 2 0 0 0
./CONANIM03_user.sh
/usr/bin/robot/pipe /tmp/robot_pipe 9 2 1 0 0

autotrack color scripts use uses '-2 5 0'
        /usr/bin/robot/pipe /tmp/robot_pipe -2 5 0 0 0
 /usr/bin/robot/autotrack_pic 2 0 0 "$2"
 /usr/bin/robot/sleep 100
        /usr/bin/robot/pipe /tmp/robot_pipe -2 5 1 0 0

image view code uses uses '-2 3 0'
 /usr/bin/robot/pipe /tmp/robot_pipe -2 3 0 0 0
 /usr/bin/robot/imageviewer -f "$1" -i "$2" -c
 /usr/bin/robot/pipe /tmp/robot_pipe -2 3 1 0 0

From play_audio_noui.sh uses '-2 0 0' and '-4 3 0' command
 /usr/bin/robot/pipe /tmp/robot_pipe -2 0 0 0 0
 /usr/bin/robot/pipe /tmp/robot_pipe -4 3 0 0 0
 /usr/bin/robot/sleep 750
 /usr/bin/robot/audioplayer -q 0 -f "$1" -c "$2" -e "$3" -n 0
 /usr/bin/robot/pipe /tmp/robot_pipe -2 0 1 0 0

play_video.sh uses '-2 1 0' command
/usr/bin/robot/pipe /tmp/robot_pipe -2 1 0 0 0
/usr/bin/robot/videoplayer -f "$1" -c "$2" -e "$3"
/usr/bin/robot/pipe /tmp/robot_pipe -2 1 1 0 0

start_sound_memo.sh ,record_audio_start.sh, and
record_video_start.sh all use '-2 2 0' commands:-
/usr/bin/robot/pipe /tmp/robot_pipe -2 2 0 0 0
/usr/bin/robot/takemovie -s1 -t6 -e "$1" 
/usr/bin/robot/pipe /tmp/robot_pipe -2 2 1 0 0

take_photo.sh,take_photo_manual.sh,take_photo_timer.sh,track_color.sh
all use '-2 4 0' commands:-
/usr/bin/robot/pipe /tmp/robot_pipe -2 4 0 0 0
/usr/bin/robot/capture_pic 0 1 1
/usr/bin/robot/pipe /tmp/robot_pipe -2 4 1 0 0

BUT take_photo_color.sh
        /usr/bin/robot/pipe /tmp/robot_pipe -2 5 0 0 0
 /usr/bin/robot/autotrack_pic 4
        /usr/bin/robot/pipe /tmp/robot_pipe -2 5 1 0 0

So maybe you can have a go at trying some of the other combinations to see if any of them work for you. Ideally you need the switch inputs to be read and the xxx_VAR files updated by the RSMedia program running on Linux board BUT you dont want the automatic body cons to be run.
 Another possibility for you is to send the '-2 1 0' before waiting for the key/button presses then once you detect a button press send the '-2 1 1' before you execute the action for that button.
 
If anyone else has any info about how these paramaters work then please let us know!!

Santa Matt wrote "Also I put it in this forum so others smarter than me could use what we figure out and progress the state of RS Media programming another step. Sometimes it is easier to send a private message or an Email, especially if also sending a file or group of files. But a script I figured we could post for all to see. :) Next time I will also send you a tickler to stuff I post public about stuff we're discussing. "
   I agree that putting all this is the forum is the best. When I said 'send me a PM' I meant to remind me to have a look at the forum - cos I missed you post for a few weeks!!
Cheers
   Helibot