Download Control of a Model Sized Hovercraft

Transcript
I
~
THE UNIVERSITY OF
NEW SOUTH WALES
SYDNEY' AUSTRALIA
if (module status != 0) {
rtl_printf("Thread initialisation failed: dtoa status
%d\n",module status);
return module status;
}
return 0;
1* module destroy *1
void cleanup_module (void)
{
pthread_delete_np(sample_thread);
pthread_delete_np(control_thread) ;
pthread_delete_np(dtoa_thread);
rnbuff_free("control_loop", (void *)cloop);
CDSM_done();
1* sampling thread code *1
void *sample_code(void *arg)
{
struct sched_param p;
hrtime t now;
long interval;
now
=
gethrtime();
p.sched_priority = 1;
pthread_setschedparam(pthread_self(),SCHED FIFO,&p);
pthread_setfp_np(pthread_self(),l);
interval = (long) (cloop->dt * 1000000000.0);
pthread_make_periodic_np(pthread_self(),now,interval);
while (1) {
pthread_wait np();
if (cloop->cstate) sample(cloop);
Ilrtl printf("debug message: %d \t %d\n",cloop->cstate,
cloop->calibrate_count);
pthread_wakeup_np(control_thread);
return 0;
1* controller thread code *1
void *control code(void *arg)
{
struct sched_param p;
p.sched_priority = 1;
pthread_setschedparam(pthread_self(),SCHED FIFO,&p);
pthread_setfp_np(pthread_self(),l);
while(l) {
pthread_suspend_np(pthread_self());
II run 'control' if not in stop mode
if (cloop->cstate) control(cloop);
32