A Simple NQC Code Repository
============================
Semaphores
----------
Robert Munafo posted [semaphore locking code] which avoids the "lockstep
starvation" problem...
| int lock; // the semaphore
| #define TASK_BIT(task_num) (1 << task_num)
|
| // this is written as if subroutines were legal in NQC, actually
| // you would implement it as an inline function or a macro
| void acquire_lock(int task_num)
| {
| while(true)
| {
| // wait for lock to be clear
| while(lock);
|
| // try to own it
| lock |= TASK_BIT(task_num);
|
| // see if we own it
| if (lock == TASK_BIT(task_num)) {
| return;
| } else {
| lock &= ~TASK_BIT(task_num);
| Sleep(task_num);
| }
| }
| }
<</robotics/rcx/nqc/?n=179>> <</robotics/?n=7799>>
-------------------------------------------------------------------------------
Motor Timing
------------
Dave Baum posted some </news/raw.cgi?lugnet.robotics.rcx.nqc:123 code
snippets> which could be used to implement an |OnFwdFor(motors)| and
|OnRevFor(motors)|...
| void OnFwdFor(const int m, const int &t) { Fwd(m); OnFor(m, t); }
| void OnRevFor(const int m, const int &t) { Rev(m); OnFor(m, t); }
<</robotics/rcx/nqc/?n=123>>
-------------------------------------------------------------------------------
RoboTag
-------
Matthew Miller posted </news/raw.cgi?lugnet.robotics:57 RoboTag version 0.8>
with an explanation and NQC source...
<</robotics/?n=57>>
-------------------------------------------------------------------------------
Using the Timer to Get Un-stuck
-------------------------------
Dave Baum posted </news/raw.cgi?lugnet.robotics:1019 code> for a
[line-following robot] in response to a question about the |timer()|
function and determining whether a robot is stuck...
<</robotics/?n=1019>>
-------------------------------------------------------------------------------
Using the Light Sensor as a "Radar"
-----------------------------------
Ben Williamson posted a </news/raw.cgi?lugnet.robotics:2765 RadarBot program>
for robots in which the [light sensor] is used as a "radar"...
<</robotics/?n=2765>>
-------------------------------------------------------------------------------
Using the IR Port as a Proximity Detector
-----------------------------------------
David Chen posted </news/raw.cgi?lugnet.robotics:2538 code and documentation>
in a program called "Ping" demonstrating the fact that the RCX's IR port,
when used as an {emitter coupled with a light sensor as a receiver}, can be
used as a [Proximity Detector]...
<</robotics/?n=2538>>
-------------------------------------------------------------------------------
Homing with the IR Tower
------------------------
Hao-yang Wang posted </news/raw.cgi?lugnet.robotics:5784 code and
documentation> for IR homing and navigation...
<</robotics/?n=5784>> |