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 / 3980
3979  |  3981
Subject: 
Brickos c++ threads problem
Newsgroups: 
lugnet.robotics.rcx.legos
Date: 
Thu, 9 Feb 2006 15:28:14 GMT
Viewed: 
9609 times
  
:Hi.
I'm currently working on a thesis using Brickos 0.9.0.

I succeeded in writing, compiling and uploading c
code.
When I tried to convert the SAME program in c++
(changing extension from .c to .cpp) and eventually
including a library such as <c++/MotorPair.H>, it
compiles and uploads BUT RCX dies after an instant, no
button works, no response to remote, no sound, and I
had to remove batteries to reload ROM firmware!
I think this problem is related to thread management.
I attach the sources:
- Test1.c is the C code
- Test2.cpp is the equivalent C++ code.

Thank you so much.

Danny

**************************************************************************
Test1.c
**************************************************************************
#include <conio.h>
#include <unistd.h>
#include <tm.h>
#include <lnp/lnp.h>
#include <dmotor.h>

int MotorSpeed=255;
int Spin();
int CheckMessage();

/* Robot spins */
int Spin() { //spin thread
  while (!shutdown_requested())
  {
    motor_a_dir(rev);
    motor_c_dir(fwd);
    motor_a_speed(MotorSpeed);
    motor_c_speed(MotorSpeed);
    lcd_number(MotorSpeed,unsign,e0);
    msleep(1);
  }
  return 0;
}

/* Remote control of motor velocity */
int CheckMessage() { //remote control thread
  while (!shutdown_requested())
  {
    if (get_msg()==3) if(MotorSpeed+5<=MAX_SPEED)MotorSpeed+=5;
    if (get_msg()==1) if(MotorSpeed-5>=MIN_SPEED)MotorSpeed-=5;
    if (get_msg()==2) MotorSpeed=125;
  }
  return 0;
}


int main(int c, char **v)
{

  execi(CheckMessage, 0, 0, PRIO_LOWEST, DEFAULT_STACK_SIZE);
  execi(Spin,         0, 0, PRIO_LOWEST, DEFAULT_STACK_SIZE);
  while(!shutdown_requested()) msleep(100);
  return 0;
}
********************************************************************
Test2.cpp
********************************************************************
#include <conio.h>
#include <unistd.h>
#include <tm.h>
#include <lnp/lnp.h>
#include <dmotor.h>
#include <c++/MotorPair.H>

int CheckMessage(int, char**);
int Spin(int, char**);

int MotorSpeed=125;
MotorPair m(Motor::A, Motor::C);


/* Robot spins */
int Spin(int c, char *v[]) { //spin thread
  while (!shutdown_requested())
  {
    m.right(MotorSpeed);
    lcd_number(MotorSpeed,unsign,e0);
    msleep(1);
  }
  return 0;
}

/* Remote control of motor velocity */
int CheckMessage(int c, char *v[]) { //remote control thread
  while (!shutdown_requested())
  {
    if (get_msg()==3) if(MotorSpeed+10<=MAX_SPEED)MotorSpeed+=10;
    if (get_msg()==1) if(MotorSpeed-10>=MIN_SPEED)MotorSpeed-=10;
    if (get_msg()==2) MotorSpeed=125;
  }
  return 0;
}


int main(int c, char *v[])
{

  execi(CheckMessage, 0, 0, PRIO_LOWEST, DEFAULT_STACK_SIZE);
  execi(Spin,         0, 0, PRIO_LOWEST, DEFAULT_STACK_SIZE);
  while(!shutdown_requested()) msleep(100);
  return 0;
}



Message has 1 Reply:
  Re: Brickos c++ threads problem
 
(...) Danny, I've not used C++, but I have seen problems like this. For me, it happened when the firmware in my brick didn't match the firmware I compiled the program to use. However, it doesn't sound like that's the problem your having. I'd suggest (...) (18 years ago, 13-Feb-06, to lugnet.robotics.rcx.legos)

3 Messages in This Thread:

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

Custom Search

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