CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Need suggestions for control/variable storage structures

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Sergeant82d



Joined: 01 Nov 2009
Posts: 55
Location: Central Oklahoma

View user's profile Send private message

Need suggestions for control/variable storage structures
PostPosted: Fri May 06, 2011 5:54 am     Reply with quote

I am working on a Radio Controlled robot lawnmower - I live on a farm and have a very large yard - which I hope to eventually make autonomous. I want to be sure I make the program extensible. I have the basic functionality down (finally!), and am trying to expand my programming ability by incorporating additional features.

I am including a variety of error messages & display LEDs, for one thing, and am trying to figure out a logical hierarchy for controlling them. I will be using one or more Maxim MAX7221 SPI LED Controllers, and I plan to use one segment line from the '7221 per sub-system. I have the hardware working, no problems there, but I want to organize the control logic so it is uniform and expandable.

I am thinking about an array of structs, each made up of three other struct arrays, as follows:

Code:

#define NUMBER_OF_MOTORS      4
#define NUMBER_OF_ENGINES     3
#define NUMBER_OF_MCUS        7

struct MOTOR[ NUMBER_OF_MOTORS ] {
   temperature : 16
   speed : 16
   voltage : 8
   current : 8
   is_running : 1
   is_over_voltage : 1
   is_over_current : 1
   is_over_temperature : 1
   is_over_speed : 1
   has_CAN_comms : 1
   }

struct ENGINE[ NUMBER_OF_ENGINES ] {
   temperature : 16
   speed : 16
//   voltage : 8
//   current : 8
   is_running : 1
//   over_voltage : 1
//   over_current : 1
   is_over_temperature : 1
   is_over_speed : 1
   has_CAN_comms : 1
   }

struct MCU[ NUMBER_OF_MCUS ] {
   temperature : 16
   voltage : 8
   current : 8
   has_power : 1
   is_over_voltage : 1
   is_over_current : 1
   is_over_temperature : 1
   has_CAN_comms : 1
   }

struct LOCATION[ item_location ] {   // e.g.   front_left.motor.temperature = 235
   struct MOTOR[]                    // e.g.   middle_engine.mcu.has_power = TRUE
   struct ENGINE[]                    // e.g.   master_mcu.has_CAN_comms = TRUE
   struct MCU[]                   // e.g.   right_rear.motor.speed = 1250                  // Captured pulses
   }

//==========================================

typedef enum {
   rear_left,
   front_left,
   front_right,
   rear_right,
   left_engine,
   middle_engine,
   right_engine,
   master_mcu,
   engine_mcu,
   contact_sensor_mcu
   }; item_location


While this looks like it will work, it also looks like it will take up a lot of RAM. I am using an 18F46K80 and have 3.8KB, but am already using half of it. Again, not a show stopper, as I am looking for something that works, but I also would like something that makes sense.

The actual members of the structs are not important as I am certain they will change as the execution is refined, but does this look like a reasonable solution?

Thanks for your time,
Brad
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group