Orange
Posts: 46
Joined: Tue Jan 24, 2012 6:41 am

Diorama Scripting Language

Sun Mar 09, 2014 9:01 pm

I've created an easy to use multi-tasking scripting language to control dioramas and other things. See this video for a quick demo:

https://plus.google.com/110265018208679 ... QvzTHeYGxh

The program was written in C++ and uses WiringPi for gpio, SDL Mixer for audio and ServoBlaster for multi PWM. To show you how simple it is to use this is the script that runs the demo in the video above:

Code: Select all

# Title:  Minecraft Steve Diorama
# Author: Scott Vincent
# Date:   March 2014
#
:main
rangemap_pwm 16 1.3 11.3
play_loop minecraft/music.wav
start Face Forwards
start Face Backwards 
start Say No
wait_press 4
exit

:Face Forwards
wait_press 0
start Green On
play minecraft/hi.wav
output_pwm 16 5 
wait .8
stop_sound minecraft/hi.wav
output_low *
wait_release 0
repeat

:Face Backwards
wait_press 1
start Blue On
play minecraft/bye.wav
output_pwm 16 100
wait .8
stop_sound minecraft/bye.wav
output_low *
wait_release 1
repeat

:Say No
wait_press 2
start Flash Red
play minecraft/monster.wav
start_wait Shake Head
start_wait Shake Head
start_wait Shake Head
start_wait Shake Head
stop_sound minecraft/monster.wav
stop_pwm *
wait_release 2
repeat

:Shake Head
output_pwm 16 0
wait .15
output_pwm 16 10
wait .15

:Flash Red
random_pwm_loop 5 0 100 .01
random_pwm_loop 8 0 100 .01
random_pwm_loop 11 0 100 .01
random_pwm_loop 14 0 100 .01

:Green On
output_high 6
output_high 9
output_high 12

:Blue On
output_high 7
output_high 10
output_high 13
This is my help file that includes the list of commands available to use in scripts:

Code: Select all

Diorama v1.0        Scott Vincent        February 2014

GPIO input and output pins should be specified using wiringPi numbering,
i.e. pin 0 is physical pin 11 on the Raspberry Pi connector.

PWM output uses ServoBlaster and only pins 0 to 16 may be used. Again,
wiringPi numbering should be used.

WiringPi Pin->Physical Pin on Main Connector
  0->11, 1->12, 2->13, 3->15, 4->16, 5->18, 6->22, 7->7, 8->3, 9->5, 10->24,
  11->26, 12->19, 13->21, 14->23, 15->8, 16->10

WiringPi Pin->Physical Pin on Auxilliary Connector (Rev. 2 boards only)
  17->3, 18->4, 19->5, 20->6

http://wiringpi.com
https://github.com/richardghirst/PiBits/tree/master/ServoBlaster

When using PWM to drive LEDs a value of 0 sets the LED fully off (0%) and a
value of 100 sets it fully on (100%).

When using PWM to drive servos you should first use the output_pwm command to
determine the minimum and maximum rotation values for your servo. You should
then use the rangemap_pwm command to set the discovered range and then revert
to using values between 0 and 100 for all PWM commands to this servo where a
value of 0 will set the servo to its minimum rotation and a value of 100 will
set the servo to its maximum rotation. A good starting point for servos is to
set the minimum to 2.5 and maximum to 12.5.

Important note: There is no idle_timeout set on ServoBlaster so if you use
the output_pwm command on a servo and leave it in the same position for long
periods of time the servo may get warm. To protect your servo you should also
use the stop_pwm command after a short delay.

Command List
============

General
-------
  # Comment              This is a comment.
  :main                  Define main activity. This activity is started when
                         the script first runs.
  :myjob                 Define a sub-activity.
  start myjob            Start a sub-activity.
  start_wait myjob       Start a sub-activity and wait for it to complete.
  stop myjob             Interrupt and stop a sub-activity.
  wait 1.5               Pause this activity for the specified number of
                         seconds.
  repeat                 Repeat this activity.
  exit                   Stop all activities and quit.

Audio
-----
  play mywavfile         Play sound. Format must be 48KHz 16-bit stereo WAV.
  play_loop mywavfile    Play in a continuous loop.
  play_wait mywavfile    Play sound and wait for it to complete.
  pause mywavfile        Pause sound.
  pause *                Pause all currently playing sounds.
  resume mywavfile       Resume playing sound.
  resume *               Resume all currently paused sounds.
  stop_sound mywavfile   Stop playing sound.
  stop_sound *           Stop all sounds.
  volume 7.5 mywavfile   Set volume of sound in range 0 to 10.
  volume 10 *            Set volume of all sounds.
  fadeout 2.5 mywavfile  Fade sound out over the specified number of seconds.
  fadeout 5 *            Fade out all currently playing sounds over the
                         specified number of seconds.

GPIO
----
  wait_press 1           Wait for switch 1 to be pressed.
                         Note: Internal pull-up resistor will be enabled.
  wait_release 1         Wait for switch 1 to be released.
                         Note: Internal pull-up resistor will be enabled.
  wait_high 1            Wait for input 1 to go high.
  wait_low 1             Wait for input 1 to go low.
  output_high 1          Set output 1 high.
  output_high *          Set all defined outputs high.
  output_low 1           Set output 1 low.
  output_low *           Set all defined outputs low.
  output_pwm 1 50        Set output 1 to PWM value in range 0 to 100.
  output_pwm * 50        Set all PWM outputs to PWM value in range 0 to 100.
  rangemap_pwm 1 2.5 12.5
                         Setting output 1 to PWM value 0 will now equate to a
                         real PWM value of 2.5 and setting it to PWM value 100
                         wil now equate to a real PWM value of 12.5.
  random_pwm 1 15 100 0.025 7.5
                         Set output 1 to a random PWM value between 15 and 100
                         every 25ms for a total duration of 7.5 seconds.
  random_pwm_loop 1 15 100 0.025
                         Set output 1 to a random PWM value between 15 and 100
                         every 25ms continuously.
  linear_pwm 1 5 95 7.5  Vary PWM linearly from 5 to 95 for a total duration
                         of 7.5 seconds.
  linear_pwm_loop 1 5 95 7.5
                         Vary PWM linearly from 5 to 95 continuously with each
                         cycle taking 7.5 seconds.
  sine_pwm 1 15 85 0 360 7.5
                         Vary PWM between 15 (at -90 degrees) and 85 (at 90
                         degrees) using a sine wave that varies from 0 to 360
                         degrees for a total duration of 7.5 seconds.
  sine_pwm_loop 1 15 85 0 360 7.5
                         Vary PWM between 15 (at -90 degrees) and 85 (at 90
                         degrees) using a sine wave that varies from 0 to 360
                         degrees continuously with each cycle taking 7.5
                         seconds.
  stop_pwm 1             Stop PWM on output 1.
  stop_pwm *             Stop PWM on all defined PWM outputs.
========================================
If anyone has ideas for improvements/enhancements please post them here.
Thanks

Orange
Posts: 46
Joined: Tue Jan 24, 2012 6:41 am

Re: Diorama Scripting Language

Tue Mar 11, 2014 10:50 am

No interest at all? I'm shocked. Maybe my use of the word diorama has put people off. This can be used to control anything where you have any mix of switches, servos, LED's (with variable brightness support) and sound samples. You can develop scripts using a simple text editor and run them direct from the command line so no GUI needed. It also supports multi-tasking so you can run any number of activities in parallel without any complicated programming.

simplesi
Posts: 2327
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK
Contact: Website

Re: Diorama Scripting Language

Thu Apr 03, 2014 8:21 am

Hi Steve

I definitley think its the word "diorama" :)

I've never heard of it :)

Also, lack of any link to try it out might also have some influence on lack of uptake :)

Simon
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter

User avatar
joan
Posts: 15791
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Diorama Scripting Language

Thu Apr 03, 2014 8:42 am

simplesi wrote:Hi Steve

I definitley think its the word "diorama" :)

I've never heard of it :)

Also, lack of any link to try it out might also have some influence on lack of uptake :)

Simon
The word should be familiar to USA citizens. They are used in junior and middle schools. Just watch the Simpsons.

User avatar
piglet
Posts: 943
Joined: Sat Aug 27, 2011 1:16 pm

Re: Diorama Scripting Language

Thu Apr 03, 2014 9:46 am

I just thought "diarrhoea". Sad but true.

Orange
Posts: 46
Joined: Tue Jan 24, 2012 6:41 am

Re: Diorama Scripting Language

Thu Apr 10, 2014 10:04 pm

simplesi wrote:Hi Steve

I definitley think its the word "diorama" :)

I've never heard of it :)

Also, lack of any link to try it out might also have some influence on lack of uptake :)

Simon
Ah, I posted the link for people to try it out on my other post here:

http://www.raspberrypi.org/forums/viewt ... co#p522575

Return to “General discussion”