Water Clock Cleanup (#1711)

* Cleaned up Water Clock and added C interface support for message subscriptions

* Added support for message publishers in C interface

* Revert "Added support for message publishers in C interface"

This reverts commit e3233891d7.
This commit is contained in:
Pherring04 2024-05-23 10:30:56 -05:00 committed by GitHub
parent 5219c1d279
commit d997759a6d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 11 additions and 10 deletions

View File

@ -14,11 +14,11 @@ Assumptions:
* Buckets and spouts are perfectly cylindrical.
### A Brief History
The water clock (or clepsydra to the ancient Greek) is a device used to measure time through the displacement of water. It is not known precisely when the earliest water clocks were developed, but they have been discovered to exist in various parts of the world as early as the 16th century BC. These early designs were relatively simple compared to later designs, consiting of a bowl with markings to indicate time passing as the bowl either filled or drained.
The water clock (or clepsydra to the ancient Greek) is a device used to measure time through the displacement of water. It is not known precisely when the earliest water clocks were developed, but they have been discovered to exist in various parts of the world as early as the 16th century BC. These early designs were relatively simple compared to later designs, consisting of a bowl with markings to indicate time passing as the bowl either filled or drained.
Water clocks remained a prominent timekeeping device until the 17th century when better methods of timekeeping were developed. Over those many centruies, different cultures innovated on the design of the early water clocks. Of particular note were the contributions of the Greek inventor Ctesibius in the 3rd century BC. Ctesibius innovated on the water clock by making it largely automatic. Prior to Ctesibius, water clocks needed to be consistently refilled/emptied by hand. Furthermore, if a water clock had indicators marking the position of the sun, they would need to be manually adjusted for different seasons. Ctesibius automated both these processes.
Water clocks remained a prominent timekeeping device until the 17th century when better methods of timekeeping were developed. Over those many centruies, different cultures innovated on the design of the early water clocks. Of particular note were the contributions of the Greek inventor Κτησιβιος (Ctesibius) in the 3rd century BC. Κτησιβιος innovated on the water clock by making it largely automatic. Prior to Κτησιβιος, water clocks needed to be consistently refilled/emptied by hand. Furthermore, if a water clock had indicators marking the position of the sun, they would need to be manually adjusted for different seasons. Κτησιβιος automated both these processes.
Ctesibius automated the draining process with a siphon akin to a Pythagorean cup. This siphon would empty over a water wheel, which powered a series of gears that would turn a cylinder. The cylinder had a row of irregular rings drawn around it, meant to correlate with the position of the sun throughout the seasons. Each day, as the water clock would fill it would accurately indicate the position of the sun, drain itself at the end of the day, and adjust the cylinder to be accurate for the next day.
Κτησιβιος automated the draining process with a siphon akin to a Pythagorean cup. This siphon would empty over a water wheel, which powered a series of gears that would turn a cylinder. The cylinder had a row of irregular rings drawn around it, meant to correlate with the position of the sun throughout the seasons. Each day, as the water clock would fill it would accurately indicate the position of the sun, drain itself at the end of the day, and adjust the cylinder to be accurate for the next day.
### Building the Simulation
After building trick, in the SIM\_waterclock directory run the command **trick-CP** to build the sim. When it's complete, you should see:

View File

@ -24,8 +24,6 @@ dyn.waterclock.timer_bucket_diam = 45.0
dyn.waterclock.total_ticks = 60
trick.message_unsubscribe(trick_message.mcout)
# ==========================================
# Start the Satellite Graphics Client
# ==========================================

View File

@ -2,7 +2,7 @@
PURPOSE: ( Water Clock Numeric Model )
**************************************************************************/
#ifndef WATRERCLOCK_NUMERIC_H
#ifndef WATERCLOCK_NUMERIC_H
#define WATERCLOCK_NUMERIC_H
#include "waterclock.h"
@ -10,10 +10,10 @@ PURPOSE: ( Water Clock Numeric Model )
#ifdef __cplusplus
extern "C" {
#endif
int waterclock_integ(WATERCLOCK*);
int waterclock_deriv(WATERCLOCK*);
double waterclock_tick_change(WATERCLOCK*);
double waterclock_overflow_timer(WATERCLOCK*);
int waterclock_integ(WATERCLOCK* WC);
int waterclock_deriv(WATERCLOCK* WC);
double waterclock_tick_change(WATERCLOCK* WC);
double waterclock_overflow_timer(WATERCLOCK* WC);
void waterclock_update_water_level(WATERCLOCK* WC);
#ifdef __cplusplus
}

View File

@ -115,7 +115,10 @@ double waterclock_tick_change( WATERCLOCK* WC ) {
if( (WC->current_tick < WC->total_ticks) && (WC->current_tick >= 0) )
{
WC->current_tick += 1;
void * sub_ptr = message_get_subscriber("cout");
message_remove_subscriber(sub_ptr);
message_publish(MSG_NORMAL, "Tick %d, Sim Time %f, Water Level %f\n", WC->current_tick, exec_get_sim_time(), WC->timer_water_level) ;
message_add_subscriber(sub_ptr);
}
else
fprintf(stderr, "ERROR, SOMETHING WENT VERY WRONG!\n" ) ;