To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.nqcOpen lugnet.robotics.rcx.nqc in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / NQC / code

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);
    }
  }
}
  Re: NQC 2.0 and some math questions
 
Your proposed solution is susceptible to the "lockstep starvation" problem. Lockstep starvation happens when two tasks try to get the lock at the same time and execute the same code in lock step, like so: task 1: lock |= 2; task 2: lock |= 4; task (...) (25 years ago, 2-Oct-99, to lugnet.robotics.rcx.nqc)
  bug in semaphore code (was Re: Announce: NQCIPC update
 
Your semaphore acquire algorithm isn't too good. Here is your code: #define sem_acquire(s) until (s == 0); s = 1; If two tasks are waiting for the semaphore at the same time, it is quite likely that both will get it: // (s is currently nonzero) task (...) (25 years ago, 29-Oct-99, to lugnet.robotics)


Motor Timing

Dave Baum posted some 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); }
  Re: NQC 2 Request
 
(...) If anyone wants to add these functions into their own code... 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); } These should be efficient - everything will be (...) (25 years ago, 15-Sep-99, to lugnet.robotics.rcx.nqc)


RoboTag

Matthew Miller posted RoboTag version 0.8 with an explanation and NQC source...

  RoboTag version 0.8 -- explaination & NQC source
 
/* Matthew's RoboTag 0.8 for Lego Mindstorms. * * written in NQC version 0.5b1 -- (URL) * * Copyright (c) 1998 Matthew Miller. You're free to use and modify this as * you wish. You can also redistribute it, but please give me credit and * don't make (...) (26 years ago, 6-Oct-98, to lugnet.robotics)


Using the Timer to Get Un-stuck

Dave Baum posted code for a line-following robot in response to a question about the timer() function and determining whether a robot is stuck...

  Re: NQC Code
 
(...) I'm going from memory here - sorry if I goof something up.... There are three timers (0, 1, and 2). They are free running at 10Hz (100ms per tick). They do not run while the RCX is "off", but they do retain their count. You can clear a timer (...) (26 years ago, 3-Dec-98, to lugnet.robotics)


Using the Light Sensor as a “Radar”

Ben Williamson posted a RadarBot program for robots in which the light sensor is used as a “radar”...

  Re: simple but functional radar
 
(...) Chris, I built a little RadarBot just like yours (very minimalist, I love it :) and wrote some NQC code to drive it around my kitchen floor. It really zooms, until the left wheel inevitably falls off. :) The program below might help you get (...) (26 years ago, 14-Jan-99, to lugnet.robotics)


Using the IR Port as a Proximity Detector

David Chen posted 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...

  IR Port as Proximity detector.
 
Someone (Can't remember who, so unfortunately unable to give credit for the idea appropriately) posted the fact that the IR port used as a emitter coupled with the Light Sensor unit as the reciever can be used as a IR proximity sensor. Seemed like a (...) (26 years ago, 8-Jan-99, to lugnet.robotics)


Homing with the IR Tower

Hao-yang Wang posted code and documentation for IR homing and navigation...

  Homing with the IR Tower
 
A while ago I was intrigued by the soda can retrieval challenge. Particularly because at that time I had built two different designs of grip-and-lift claws: The first is based on the bar-code truck claw. It uses the flex system and lifts things (...) (25 years ago, 23-Jul-99, to lugnet.robotics)
All text, images, or trademarks in this document are the intellectual property of their respective owners.


©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR