smart_PTC_monitor beta code release
Download: https://dl.dropbox.com/u/17455717/smart_PTC_monitor_template.beta.8.27.12.c
[edit…please redownload if you grabbed the code before 1:45pm 8/31, I had some critical stuff commented out before then]
Ok, I’ve got the RobotC code used in my smart_PTC_monitor developed to a point where I would let others play with it. I originally used a single timed iterative loop that ran in the same task as autonomous and user modes. I decided to create a separate task that simplifies the user interface so normal programming can occur without any of my constraints. When done, the user functions are easily inserted into my template to seamlessly add the PTC monitor protection capability. The program is self documented with liberal commenting but I am sure people will have a lot of questions. I am putting it out without fully testing all the possible motor configurations to get early user feedback and if it proves to have utility, I will put out a more mature version that includes user feedback.
Please post your comments to the Vex forum thread where the program is introduced. Thanks
Below is a copy of the introduction comments in the program:
//*************************************************************************************************************** // smart_PTC_monitor_template.beta.8.27.2012.c Rev 0
// This program is an open source beta version of a competition template for Sack Attack. It adds a task // called smart_PTC_monitor which uses current and PTC temperature models to manage a current_limiter function // which can keep hardware PTC fuses in the motors,cortex and power expander from ever tripping.
// Program Author: Chris Siegert aka Vamfun on the Vex forums. // see my blog: vamfun.wordpress.com for model details and vex forum threads on subject // email: [email protected] // Mentor for team 599 Robodox and team 1508 Lancer Bots
// Teams are authorized to freely use this program , however, it is requested that improvements or additions be // shared with the Vex community via the vex forum. Please acknowledge my work when appropriate. Thanks
// Scope and limitations: // Program assumes that servo currents are zero. If servo position is known, then currents can be modeled. // Testing has been limited to 393 motors and 3wire motors, however, the program handles 269 motors. // Periodic updates to the models will be made and posted on the Vex forum as more testing is done. // Program handles the Power Expander PTC when the ports are entered with provided #defines // All other motor ports are automatically configured to calculate the correct currents for each PTC
// Basic Instructions: // Write your program as you normally would. When done, put your autonomous code in place of my_autonomous() // and your user code in place of my_user(). Then do a find and replace to change all the “motor” functions to // “motor_input” i.e. motor[Left_motor] –> motor_input[Left_motor].
// Put all your encoder speed calculations into void compute_speeds() function and assign speeds to M[port].speed variable. // You can read these speeds from the global array whenever you need them. This loop runs at about 100ms update rate.
// Use a #define or switch to create a // PTC_monitor_engage boolean and set true to engage the monitor.
// Tell the program which ports are used by the Power Expander as shown in the example below: // #define PE_CH1 UNUSED // if used put port number …. i.e. PE_CH1 port1 else put the #define UNUSED
// #define PE_CH2 Right_drive_motor //use setup names
// #define PE_CH3 port3 //use port name
// #define PE_CH4 1 // use integer = to port number -1. This is motor port2
// Initialize the PTC temperatures using these #defines: // #define T_0_DEG_F (72.) //Set robot ambient temperature here. If you are in a hot gym…this might be 85 deg
// #define T_M (100.) //nominally 100 deg C =Setpoint temperature for the PTC current monitor. This can be lowered if your hardware PTCs are tripping before the monitor current limit is engaged. Or it can be increased to delay current limit engagement if it is occuring too soon.
// Motor currents and PTC temperature data are held in a global state matrix M] which is a structured array that contains // the motor PTC/current data in the first 10 elements (index 0 to 9) and the non motor PTC’s data in the next three elements. // M[10] , M[11] and M[12] pertain to the cortex1_5,cortex6_10 and power expander PTC states respectively.
// Program uses two update rates: The current_limiter updates at PTC_TASK_DELAY_MS which is 15ms // and the temperature calculations are set to run at about 6 times {PTC_TASK_DELAY_MS + subtasks delays) ~= 100ms. //****************************************************************************************************************