View unanswered posts | View active topics It is currently Wed Oct 01, 2014 8:26 pm






Reply to topic  [ 11 posts ] 
Have Events been enabled in RobotC 
Author Message
Novice

Joined: Sun Feb 04, 2007 12:48 am
Posts: 69
Location: Australia
Post Have Events been enabled in RobotC
I last visited this topic about 4-6 months ago in the old forum. It took a little while to get clarification, but at the time Dick Swan posted a very detailed response (one of the reasons I'd like to see the old forum migrated across or accessible) explaining that events were not correctly implemented in the RCX firmware. While Robolab and NQC had implemented some sort of work around which made them appear to work with events, Dick was proposing the idea that the fault in the firmware should be corrected. At the time there were other priorities, and Dick felt the complexity of the task was very high (And, he offered me the job if I'd like to fix it. Ha Ha Ha)

Now, it took me a little while to get the structure and syntax correct at the time and I've since lost my original code. Rather than go through the same scenario again I was wondering:

1) Has the old problem with events been resolved with the RCX?
2) Is it something that is likely to be looked at or is it outside the scope of RobotC? If it is likely to be fixed what time frame is realistic?
3) Do events work with the NXT?
4) If they do can someone post a simple example using correct syntax or my old example (from old forum) if it is still correct?

Thanks
James


Wed Feb 28, 2007 9:29 pm
Profile
Creator
Creator

Joined: Fri Feb 09, 2007 9:21 am
Posts: 615
Post 
I don't remember what I posted. NXT implementaito nis same as RCX. It has events working.

As I recall, I think you wanted more generaic "OS" type of events. What is implemented is capabilities like "wait until either timeout of some kind of synchronization event / semaphore".

Refresh my memory please.


Thu Mar 08, 2007 10:10 pm
Profile
Novice

Joined: Sun Feb 04, 2007 12:48 am
Posts: 69
Location: Australia
Post 
Hi Dick,

Thanks for your response.

I don't have much more info than I posted above. Given the situation I was hoping maybe Vu Nguyen has access to the old forum and could copy some of the old messages to this new post. Alternatively, I found some old code I was playing around with. This doesn't compile in the new version but I'm pretty sure it did under the old Beta versions of RobotC.


Before anyone writes back to explain that there is simpler code to follow a line please note this is an attempt to understand and implement events.
Code:
//*!!Sensor,    S1,        LightSensLeft, sensorReflection,      ,               !!*//
//*!!Sensor,    S3,       LightSensRight, sensorReflection,      ,               !!*//
//*!!Motor,  motorA,            MotorLeft, tmotorNormal,                         !!*//
//*!!Motor,  motorC,           MotorRight, tmotorNormal,                         !!*//
//*!!                                                                            !!*//
//*!!Start automatically generated configuration code.                           !!*//
const tSensors LightSensLeft        = (tSensors) S1;   //sensorReflection   //*!!!!*//
const tSensors LightSensRight       = (tSensors) S3;   //sensorReflection   //*!!!!*//
const tMotor   MotorLeft            = (tMotor) motorA; //tmotorNormal       //*!!!!*//
const tMotor   MotorRight           = (tMotor) motorC; //tmotorNormal       //*!!!!*//
//*!!CLICK to edit 'wizard' created sensor & motor configuration.      !!*//

void LeftSensorHit();
void RightSensorHit();


task main()
{
//compileint nValueOfBlack = 34;      //This is the value of a black line

      SetEvent(0,LightSensLeft, eventTypeEnterLow);
      SetEvent(1,LightSensRight, eventTypeEnterLow);
      CalibrateEvent(0, 34, 100, 0);
      CalibrateEvent(1, 34, 100, 0);

      while (true)    // Core of the program is endless loop to drive fwd
      {
            monitor(EVENT_MASK(0)| EVENT_MASK(1))
            {
               motor[MotorLeft] = 100;  //Output Left - full speed forward
               motor[MotorRight] = 100;  //Output Right - full speed forward
            }
            catch EVENT_MASK(0)
            {
               LeftSensorHit();
            }
            catch EVENT_MASK(1)
            {
               RightSensorHit();
            }

      }
}
void RightSensorHit()
{
            motor[MotorLeft] = 0;  //Stop motors
            motor[MotorRight] = -20;  //Stop motors
            PlaySound(soundBeepBeep);  //Plays the sound "Beep Beep"
            wait1Msec(1000);      //Wait 1 seconds
            ResetEvent(1);
}
void LeftSensorHit()
{
            motor[MotorLeft] = -20;  //Stop motors
            motor[MotorRight] = 0;  //Stop motors
            PlaySound(soundBeepBeep);  //Plays the sound "Beep Beep"
            wait1Msec(2000);      //Wait 2 seconds
            ResetEvent(0);
}



Also I'm struggling to find any info about events. They don't seem to be listed in the templates section.

Thanks
James


Sun Mar 11, 2007 6:34 am
Profile
Novice

Joined: Sun Feb 04, 2007 12:48 am
Posts: 69
Location: Australia
Post 
Hi Vu,

Any chance of digging out the old post to give Dick a more informed picture of what I'm asking?

Thanks
James


Sat Mar 17, 2007 2:18 am
Profile
Novice

Joined: Sun Feb 04, 2007 12:48 am
Posts: 69
Location: Australia
Post 
Bummer,

It looks like this one was missed in Dick's last visit. :(

If one of the developers sees this, and it is not too late, can a working example of events be included in the sample files in the next release. (The syntax and structure eludes me) A simple one such as a program that simply drives fwd until a light sensor sees a black line would be great.

Or simply post an example here :D

Thanks
James


Mon Mar 26, 2007 8:31 am
Profile
Site Admin
Site Admin

Joined: Wed Jan 24, 2007 10:44 am
Posts: 439
Location: Pittsburgh, PA
Post 
I sent out set of links to him to have him respond, I hope I didn't miss this one on the email. I'll email him this link right now, sorry for the delay!

_________________
Vu Nguyen
Software Training Development Team | Webmaster
Need more support? Use the ROBOTC Ticketing system

Robotc.net| Robomatter Store | Robotics Academy | CS2N


Mon Mar 26, 2007 9:43 am
Profile
Creator
Creator

Joined: Fri Feb 09, 2007 9:21 am
Posts: 615
Post 
The following is the "tricky" code

Code:
 
while (true)    // Core of the program is endless loop to drive fwd
{
  monitor(EVENT_MASK(0)| EVENT_MASK(1))
  {
    motor[MotorLeft] = 100;  //Output Left - full speed forward
    motor[MotorRight] = 100;  //Output Right - full speed forward
  }
  catch EVENT_MASK(0)
  {
    LeftSensorHit();
   }
  catch EVENT_MASK(1)
  {
    RightSensorHit();
  }
}

This code is not what you intended. It will look forever setting up event monitoring, executing two "motor" instructions in the wait section and then exiting the event monitoring. Almost half the time will be spent in the loop outside of the "monitor" block.

I'm sure what was intended was to put long delay inside the event monitoring "section". The delay will be aborted when a event happens and the code will fall into the 'catch' clause.
So the modified code is:
Code:
 
while (true)
  monitor(EVENT_MASK(0)| EVENT_MASK(1))
  {     
      motor[MotorLeft] = 100;  //Output Left - full speed forward
      motor[MotorRight] = 100;  //Output Right - full speed forward
      wait1Msec(20000);
  }
  catch EVENT_MASK(0)
  {
    LeftSensorHit();
   }
  catch EVENT_MASK(1)
  {
    RightSensorHit();
  } 


Tue Apr 03, 2007 8:13 am
Profile
Novice

Joined: Sun Feb 04, 2007 12:48 am
Posts: 69
Location: Australia
Post 
Well Hello,

I'm back and banging on about this old chestnut again!!

I've tried to simplify the program so that it simply drives forward till it hits a line then stops. While the code compiles OK, when it runs I get the following "RobotC Exception Violation Report".

Program Slot 0, Task ID:main[0]
Error at PC:BAD-LOC +0x10F54
Task PC: Task offset 0018,
TaskState: 'Exception'
Exception Type: 'Invalid opcode(11)'

Note to Developers: Can you unlock the Exception Report dialog box so the above details can be cut & pasted rather than re-typed. It would be better for me and you as people will be more likely to post their error descriptions.

Anyway here is my code:

Code:
const tSensors LightSensLeft        = (tSensors) S1;   //sensorLightActive  //*!!!!*//
const tMotor   MotorL               = (tMotor) motorB; //tmotorNxtEncoderClosedLoop //*!!!!*//
const tMotor   MotorR               = (tMotor) motorC; //tmotorNxtEncoderClosedLoop //*!!!!*//
//*!!CLICK to edit 'wizard' created sensor & motor configuration.                !!*//

void HitLine();

const byte ev0 = 0;


task main()
{

      SetEvent(ev0,LightSensLeft, eventTypeEnterLow);
      CalibrateEvent(ev0, 34, 100, 0);

      while (true)    // Core of the program is endless loop to drive fwd
      {
            monitor(EVENT_MASK(0))
            {
               motor[MotorL] = 40;  //Output Left
               motor[MotorR] = 40;  //Output Right
               wait1Msec(20000);
            }
            catch EVENT_MASK(0)
            {
               HitLine();
            }
      }
}

void HitLine()
{
            motor[MotorL] = 0;  //Stop motors
            motor[MotorR] = 0;  //Stop motors
            PlaySound(soundBeepBeep);  //Plays the sound "Beep Beep"
            wait1Msec(2000);      //Wait 2 seconds

}


Please note it appears to setup events in the events debugger window. I'm unsure whether it configures correctly though as no samples have been posted yet. Hint. Hint :D

Thanks
James


Thu May 17, 2007 6:02 am
Profile
Rookie

Joined: Sun Apr 15, 2007 8:33 am
Posts: 40
Location: USA
Post 
Hi,

Just to let you know that I got the same error, I think that the calibrate function is the culprit!

cu.

jm.

_________________
SuntzuMaster- a French gentlemen in USA.


Sun May 20, 2007 4:04 pm
Profile
Rookie

Joined: Sun Apr 15, 2007 8:33 am
Posts: 40
Location: USA
Post 
I would like to hilight the fact that I love ROBOTC, but I think that as soon as one wants to start a real large or very technical piece of S/W then the documentation is not appropriate anymore... I have wrote s/w on different platforms from pc to mainframe and the documentation was always outstanding even in 1984/85 when I was using the very first BORLAND TURBO/PASCAL/ASSEMBLER/C... their documentation was always excellent. I think that a true technical documentation and a true language reference are more than missing... I think also that some formal information about H/W and S/W relationships could be welcome. The current post is just a symptome about that documentation issue...

I think that it is still possible to look inside all the ROBOTC header files to try to discover what functions are hidden but I do not think that is appropriate at all.

hope that one day ROBOTC.NET will provide that level of documentation that could save hours of guess work.

thanks in advance.

jm.

_________________
SuntzuMaster- a French gentlemen in USA.


Tue May 22, 2007 8:32 am
Profile
Creator
Creator

Joined: Fri Feb 09, 2007 9:21 am
Posts: 615
Post 
"CalibrateEvent" is non-functional. It was initially implemented for legacy purposes with the original RCX firmware code. When I looked at the RCX implementation, I'm pretty confident that it is broken/non-functional and never got around to writing a working version for the RCX.

With the increased power of the NXT, it would not be that difficult to write your own calibrate function if you're not happy with the default values.

Here's a sample program that I recently wrote to illustrate the event handling capabilities.

Code:
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//                                 Sample Program to Demonstrate Events
//
// Short little program to demonstrate use of Events.
//
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//
// You can monitor up to 16 events; they're numbered from 0 to 15. This program will monitor two of them. A couple of
// convenient declarations for the two events used in this sample program.
//
const byte kUserEvent1 = 1;
const byte kTimerEvent2 = 2;

//
// A couple of variables to keep track of how many times each event is triggered.
//
int nUserEvents = 0;
int nTimerEvents = 0;

void waitTest(int nDuration)
{
  //
  // There was a (incorrect) bug report that said event monitorings didn't work when a subroutine was running when
  // the event occured. This function is called while we're monitoring events and we find that everything works fine.
  //
  wait1Msec(nDuration);
  return;
}


void testEvents()
{
  ClearAllEvents();

  //
  // Need to define the two events.
  //
  //  Event 'kUserEvent1' will be user defined. That means it is set by software with a "SignalEvent" call.
  //
  //  Event 'kTimerEvent2' will be defined when the value of "timer 1" enters the high region. The timer events are
  //  use 100-msec ticks. Setting the value of "eventUpper[kTimerEvent2] = 10;" will define the upper threshold at 1,000
  //  msec (or 1 second) so the event will be triggered whenever the timer crosses the threshold greater than value 1000.
  //
  SetEvent(kUserEvent1, EST_USER_EVENT_0, eventTypePressed);
  SetEvent(kTimerEvent2, EST_TIMER_1, eventTypeEnterHigh);
  eventUpper[kTimerEvent2] = 10; // 10 ticks of 100-msec each

  while (true)
  {
    time1[T1] = 0;
    monitor (EVENT_MASK(kUserEvent1) | EVENT_MASK(kTimerEvent2))
    {
      while (true)
      {
        waitTest(2000);
        PlaySound(soundBlip);
        SignalEvent(kUserEvent1); // This code never gets executed because we wait longer than the 1 second duration
                                  // that triggers the 'kTimerEvent2'. If reduced the wait time below 1 second we'd
                                  // find that the "SignalEvent" is happening and that 'kUserEvent1' will be triggered.
      }
    }
    //
    // You can define one or more "catch" clauses. This is very much like the "try ... catch" sequence found in C++.
    //
    // A catch clause can specify a mask for the events that it will catch. Typically this is the bit mask for a single
    // event but it could be a bit map specifying multiple events.
    //
    // 'catch" clauses are evaluated in sequential order until one matches the bit map of events that have happened.
    //

    catch (EVENT_MASK(kUserEvent1))
    {
      PlaySound(soundBeepBeep);
      ++nUserEvents;
    }

    catch (EVENT_MASK(kTimerEvent2))
    {
      PlaySound(soundBeepBeep);
      time1[T1] = 0; // Need to reset the timer so that the event can trigger again.
      ++nTimerEvents;
    }

    catch
    {
      // This will "catch" all remaining events. In this case, there will be no events to captr
    }
  }

  PlaySound(soundDownwardTones);
  wait1Msec(5000);
}


task main()
{
  //
  // There was a (incorrect) bug report that said event monitorings didn't work when it were defined in a subroutine.
  // We'll test this here and find that it works fine.
  //
  testEvents();
  return;
}

//
// Above sample events were very simple. Mor typically you might define an event based on the value of one of the sensors. You
// could use "eventTypeEnterHigh", ":eventTypeEnterLow" or "eventTypeEnterNormal" to indicate whether the event is triggered
// because we entered high, low or normal (i.e. between low and high) values. For example, in line following you could use this
// to indicate whether the robot is "on the line" or to the "dark" or "light" side of the line. For a sensor event, simple use the
// value "EST_SENSOR_X" (X = 0, 1, or 2) to define based on a sensor value.
//
// Note for legacy reasons and compatibility with RCX and NXT you can only define events for first three sensors. You cannot define
// an event for the fourth NXT sensor.
[/code]


Fri Jun 22, 2007 6:28 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 11 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.