To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.legosOpen lugnet.robotics.rcx.legos in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / legOS / 941
940  |  942
Subject: 
Re: task managment
Newsgroups: 
lugnet.robotics.rcx.legos
Date: 
Fri, 17 Mar 2000 21:11:52 GMT
Viewed: 
1537 times
  
Would someone be so kind to show me through some
code snippets how to create multiple tasks using
legOS? I haven't been able to gleen this info
from the code although its probably there...

Here is some sample code using three tasks for:

1. Motor control
2. Sound control
3. Shaking the head

This runs on the Inventorbot of the Invention System.
Each task is independantly watching a sensor to control
it's actions.

Hope this helps,
Eddie C. Dost
ecd@skynet.be
--
/* file:   line1mot.c
*/

#include <conio.h>
#include <unistd.h>

#include <dsensor.h>
#include <dmotor.h>
#include <dsound.h>

#define LIGHTSENS       SENSOR_2
#define DARK_THRESH     0x40
#define BRIGHT_THRESH   0x46

#define NORMAL_SPEED (MAX_SPEED)
#define TURN_SPEED   (MAX_SPEED / 2)

static const note_t robots[] = {
{ PITCH_D4,  2 } , { PITCH_C4,  1 } , { PITCH_D4,  1 },
{ PITCH_F4,  1 } , { PITCH_D4,  1 } , { PITCH_D4,  2 },
{ PITCH_F4,  2 } , { PITCH_G4,  1 } , { PITCH_C5,  1 },
{ PITCH_A4,  2 } , { PITCH_D4,  2 } , { PITCH_END, 0 }
};

static wakeup_t
dark_found(wakeup_t data)
{
return LIGHT(LIGHTSENS) < (unsigned short)data;
}

static wakeup_t
sensor1_release(wakeup_t data)
{
return SENSOR_1 > 0xf000;
}

static wakeup_t
sensor3_release(wakeup_t data)
{
return SENSOR_3 > 0xf000;
}

static void
locate_line(void)
{
motor_c_speed (NORMAL_SPEED);
motor_c_dir (rev);

msleep(1);

cputs("run  ");
wait_event (dark_found, DARK_THRESH);
}

static void
follow_line(void)
{
while (1) {
cputs("turn ");

motor_c_speed (TURN_SPEED);
motor_c_dir (fwd);

while (dark_found(DARK_THRESH))
msleep (1000);

cputs("run  ");

motor_c_speed (NORMAL_SPEED);
motor_c_dir (rev);

wait_event(dark_found, DARK_THRESH);
}
}

int
line_task(int argc, char **argv)
{
ds_active(&LIGHTSENS);

locate_line();
follow_line();

return 0;
}

int
head_task(int argc, char **argv)
{
while (1) {
wait_event(sensor1_release, 0);

motor_a_speed (MAX_SPEED >> 1);
motor_a_dir (fwd);

sleep(5);

motor_a_dir (off);
}
}

int
music_task(int argc, char **argv)
{
while (1) {
wait_event(sensor3_release, 0);
dsound_play(robots);
wait_event(dsound_finished, 0);
}
}

int
main (int argc, char **argv)
{
execi(line_task, argc, argv, 0, 0x100);
execi(head_task, argc, argv, 0, 0x100);
execi(music_task, argc, argv, 0, 0x100);
return 0;
}



Message has 1 Reply:
  Re: task managment
 
Thanks Eddie, What kind of limit is there for active tasks? Is there a responsitory somewhere for sample programs/projects people have written? Thanks (...) (25 years ago, 17-Mar-00, to lugnet.robotics.rcx.legos)

Message is in Reply To:
  task managment
 
Would someone be so kind to show me through some code snippets how to create multiple tasks using legOS? I haven't been able to gleen this info from the code although its probably there... thanks tom (25 years ago, 17-Mar-00, to lugnet.robotics.rcx.legos)

3 Messages in This Thread:

Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact

This Message and its Replies on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

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