Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > embed Ruby or Lua

Reply
Thread Tools

embed Ruby or Lua

 
 
Paolo Bosetti
Guest
Posts: n/a
 
      04-09-2008
Gaspard, just a couple of comments.
I'm working on a similar soft-realtime application (autonomous drive of
a vehicle), and I implemented the high level logic as a Ruby
statemachine. I found that I can get a satisfying level of realtime
(including UDP stack access) by keeping a fixed pace loop like that:

while running do
slp_thr = Thread.start do sleep timestep end
#do the loop stuff here
slp_thr.join
end

It works surprisingly fine until 300-350 Hz.
Since you're running on Macs, you could also use the scheduling control
functions of the Mach kernel. For example, something like that can be
helpful:

inline do |builder|
builder.include "<mach/mach_init.h>"
builder.include "<mach/thread_policy.h>"
builder.include "<sched.h>"
builder.c '
int set_realtime(double period, double computation, double
constraint) {
uint32_t HZ = 2000000000;
struct thread_time_constraint_policy ttcpolicy;
int ret;
ttcpolicy.period=HZ*period; // HZ/160
ttcpolicy.computation=HZ*computation; // HZ/3300;
ttcpolicy.constraint=HZ*constraint; // HZ/2200;
ttcpolicy.preemptible=1;

if ((ret=thread_policy_set(mach_thread_self(),
THREAD_TIME_CONSTRAINT_POLICY,
(thread_policy_t)&ttcpolicy,
THREAD_TIME_CONSTRAINT_POLICY_COUNT)) != KERN_SUCCESS) {
fprintf(stderr, "set_realtime() failed.\n");
return 0;
}
return 1;
}

'
end

Cheers,
Paolo
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Parsing lua with Ruby Catalin Tilimpea Ruby 7 07-06-2009 01:28 AM
Ruby equivalent for Lua first-class functions? Dolazy Ruby 1 11-15-2008 03:19 PM
thread-safe ANSI-C ruby needed to replace lua jeff_alexander_44@yahoo.com Ruby 6 05-18-2007 07:37 PM
embedding: ruby vs. lua Shea Martin Ruby 10 02-06-2007 05:59 PM
Game Programming with Python, Lua and Ruby Carsten Eckelmann Ruby 3 01-13-2004 03:13 AM



Advertisments