|
The code I have taken out of HOWTO.ps
http://legos.sourceforge.net/HOWTO/HOWTO.ps
it's given at the end of the document under the name Demo.c
I have fixed some compile time errors (like mismatching process ids in the
kill call,
the function for getting button state is dbutton() and not button_state()
and
have replaced the RUN_BUTTON in the example to VIEW_BUTTON)
rest of the code is the same.
I am using legos-0.2.6
The task_swapper() task is started as follows
int main(int argc, char *argv[])
{
pid1=execi(&task_swapper, 0, NULL, 1, DEFAULT_STACK_SIZE);
}
Following is the motor driver task
/*
the motor example:
the first while loop does a simple linear speed increase
the second while loop puts the bot into a spin
the final two statements demonstrate brake and offuse
your fingers to test the difference between the two.
the whole thing loops until VIEW is pushed (see task_swapper() for control
of this)
*/
void motor_driver()
{
int rover_speed;
while(1)
{
rover_speed=0; /*realign here, otherwise you start at a negative value*/
/*speeds up the bot in linear fashion- watch out!*/
while(rover_speed < MAX_SPEED)
{
motor_a_speed(rover_speed);
motor_c_speed(rover_speed);
lcd_int(rover_speed);
motor_a_dir(fwd);
motor_c_dir(fwd);
msleep(500); /*adjust here if you need a finer differentiation*/
rover_speed+=20;
}
/*slows down the bot in linear fashion*/
while(rover_speed>=0)
{
motor_a_speed(rover_speed);
motor_c_speed(rover_speed);
lcd_int(rover_speed);
motor_a_dir(fwd);
motor_c_dir(rev);
msleep(500); /*adjust here if you need a finer differentiation*/
rover_speed-=10;
}
/*test the brake state with your fingers*/
cputs("brake");
motor_a_speed(brake);
motor_c_speed(brake);
sleep(3);
/*test the off state with your fingers*/
cputs("off");
motor_a_speed(off);
motor_c_speed(off);
sleep(3);
}
}
Thanks for your response
"Steve Hassenplug" <hassenplug@mail.com> wrote in message
news:20020709132810.21647.qmail@verizonmail.com...
> I'm no expert, but I can try to help you figure it out.
>
> Let's start with something simple. What version of LegOS are you using?
>
> How are you starting the 'task_swapper' task?
>
> What is in the 'motor_driver' task?
>
> At one time, when I was working with tasks, I seemed to have a problem
where one task would take control, and not stop. I think it may have been
the priorities of the tasks.
>
> Steve
>
> ----- Original Message -----
> From: "Shehryar Shaheen" <shehryar.shaheen@ul.ie>
> Date: Tue, 9 Jul 2002 13:21:04 GMT
> To: lugnet.robotics.rcx.legos@lugnet.com
> Subject: HOWTO Demo.c
>
> Need Help, if someone has faced such a problem or knows the fix
> please do reply.
>
> In the legOS Howto their is a demo code demo.c which has some
> task switching examples
>
> I am having trouble with the following piece of code
>
> int task_swapper()
> {
> wait_event(&button_press_wakeup,BUTTON_VIEW); /*wait for PROGRAM button*/
> wait_event(&button_release_wakeup,BUTTON_VIEW);/*wait for release*/
>
> pid2=execi(&motor_driver, 0, NULL, 2, DEFAULT_STACK_SIZE);/*start motor
> example*/
>
> wait_event(&button_press_wakeup,BUTTON_VIEW); /*wait for PROGRAM button*/
> wait_event(&button_release_wakeup,BUTTON_VIEW); /*wait for release*/
>
> kill(pid2); /*kill motor example*/
>
> motor_a_speed(off);
> motor_c_speed(off);
>
> pid3=execi(&light_sensor, 0, NULL, 3, DEFAULT_STACK_SIZE);/*start light
> example*/
>
> wait_event(&button_press_wakeup,BUTTON_VIEW); /*wait for PROGRAM button*/
> wait_event(&button_release_wakeup,BUTTON_VIEW);/*wait for release*/
>
> kill(pid3); /*kill light example*/
>
> ds_passive(&SENSOR_2); /* turn off light sensor LED (passive mode again) */
>
> pid4=execi(&touch_sensor, 0, NULL, 4, DEFAULT_STACK_SIZE);/*start touch
> example*/
>
> wait_event(&button_press_wakeup,BUTTON_VIEW); /*wait for PROGRAM button*/
> wait_event(&button_release_wakeup,BUTTON_VIEW);/*wait for release*/
>
> kill(pid4); /*kill touch example*/
>
> lcd_clear();
> sleep(1);
> cputs("reset");
> sleep(3);
> return 0;
> }
>
> after the program is started with the run button and the view button is
> pressed
> the first task (motor example pid2) starts and it works .
>
> but if I press the view button a second time the RCX hangs.
> Display gets stuck to what is already on it , no buttons work any more
> including on/off.
>
> So I have to take out the batteries and when I put them back I have to re
> install the firmaware as well.
>
> I have tried changing the button to BUTTON_PROGRAM but get the same result
> changing it to BUTTON_RUN does not work any way because if run pressed once
> the
> program is started the program stops.
>
> I have also tried using a touch sensor instead of buttons for wake up
> functions to switch
> between task but the same behaviour happens.( I have tried it quite a lot of
> times)
>
> I did a search on the mailing list too there was a post which mentioned that
> the the HOWTO is old and in the newer legOS "the buttons have been
> incorporated
> in the OS and perhaps there isn't a way to decuple them from the OS".
>
> Could this be the reason or does somone have an idea.
>
> Many Thanks
>
> Shehryar
>
> --
> _______________________________________________
> Talk More, Pay Less with Net2Phone Direct(R), up to 1500 minutes free!
> http://www.net2phone.com/cgi-bin/link.cgi?143
>
>
>
|
|
Message is in Reply To:
| | Re: HOWTO Demo.c
|
| I'm no expert, but I can try to help you figure it out. Let's start with something simple. What version of LegOS are you using? How are you starting the 'task_swapper' task? What is in the 'motor_driver' task? At one time, when I was working with (...) (22 years ago, 9-Jul-02, to lugnet.robotics.rcx.legos)
|
2 Messages in This Thread:
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|