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 / 3559
3558  |  3560
Subject: 
Re: Strange RCX startup issues
Newsgroups: 
lugnet.robotics.rcx.legos
Date: 
Tue, 9 Dec 2003 17:36:52 GMT
Viewed: 
3830 times
  
In lugnet.robotics.rcx.legos, Rand Krakora wrote:
Hello,

using brickOS v0.2.6.10...

When I declare an object of type Motor and assign it a port outside of
main() the RCX does not run the program at all, I have to remove batteries
and reload firmware to get it back to normal.

Is this related to the 2-byte offset that is skipping the register clear
that makes the motors run when they are not commanded?

This was only a problem when using certain firmware downloaders.  If you use
firmdl3, then you should be fine.

I didn't notice the motor doing anything, just no RCX operation until I
moved the definition of the Motor type object back into main().

Any insights will be appreciated, I don't mind figuring out why this
happens, just want to know if someone else already has or not.

As far as I can tell, I don't think there is any provision in BrickOS to call
the constructors and destructors of globals & staticly declared objects.

The Motor object has function pointers in it that get initialized in the
constructor.  If the constructor isn't called then these pointers won't point to
the proper code and your program will crash when you start to use the Motor
object.

Below you'll find a wrapper function that will walk through the global
constructor/destructor tables and call them upon entry/exit to your program.

HTH,

Mark

#include <config.h>
#include <c++/Motor.H>
#include <conio.h>
#include <unistd.h>

// Call the constructors & destructors of global objects

typedef void (*Ftor)();
extern "C" Ftor __ctors[], __ctors_end[];
extern "C" Ftor __dtors[], __dtors_end[];
int main2();

int main()
  {
  Ftor* f;
  int r;

  // call constructors
  for (f = __ctors; f != __ctors_end; f++)
    (*f)();

  r = main2();

  // call destructors
  for (f = __dtors; f != __dtors_end; f++)
    (*f)();

  return r;
  }

// Test motor object

Motor m(Motor::A);

int main2()
  {
  while (!shutdown_requested())
    {
    m.forward();
    m.speed(m.max);
    cputs("F");
    sleep(1);

    m.reverse();
    m.speed((m.max + m.min) / 2);
    cputs("r");
    sleep(1);
    }

  return 0;
  }



Message has 1 Reply:
  Global Objects was Strange RCX startup issues
 
Mark, This is an interesting issue. Initially, after reading your post, I was thinking that it would be easy to add this support to BrickOS. Of course, this is only partially correct. For NON Task Manager builds (therefore no Program manager), it is (...) (21 years ago, 9-Dec-03, to lugnet.robotics.rcx.legos)

Message is in Reply To:
  Strange RCX startup issues
 
Hello, using brickOS v0.2.6.10... When I declare an object of type Motor and assign it a port outside of main() the RCX does not run the program at all, I have to remove batteries and reload firmware to get it back to normal. Is this related to the (...) (21 years ago, 9-Dec-03, to lugnet.robotics.rcx.legos)

12 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