Netduino scheduler - Project Showcase - Netduino Forums
   
Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Netduino scheduler


  • Please log in to reply
13 replies to this topic

#1 kingpin2k

kingpin2k

    Member

  • Members
  • PipPip
  • 23 posts
  • LocationUSA

Posted 15 August 2010 - 07:14 AM

Instead of waiting for 500 ms before you tell your light to turn on schedule it to turn on in 500 ms and then let the scheduler turn it on. What's included: Scheduler class (currently the scheduled tasks are being stored as a linked list, if you wanna see how a linked list works) abilities: schedule Actions to occur within a certain time. schedule actions to occur within a certain time, then reoccur at a certain interval.. If you'd like to create your own Action: 1. Create a new class 2. Implement the Action class. (AKA add ": Action" after your class name in your class file) 3. Add a new value to the ActionTypes enum in the Action class, and make sure to return that in your class (the overridden method GetActionType()) - this is necessary for functionality of finding out whether or not the scheduler contains any of that type of actions currently queued. Here's the alpha release of my scheduler. Lemme know what doesn't work ;)

Attached Files


Homer: [Meeting Aliens] Please don't eat me! I have a wife and kids. Eat them!

#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 15 August 2010 - 07:24 AM

That's a nice scheduler framework. Wow. Didn't you just get your Netduino? :) One thing I should bring up...It's perfectly fine to run your code in loop on a Netduino, but .NET Micro Framework is designed to go into "low power" mode when all threads are asleep. So if you put together a scheduler that called Thread.Sleep(##ms) between scheduled events, you'd have a battery-friendly scheduler. As we work on the power management code in future Netduino firmware releases, this will become more and more beneficial. [Of course, you couldn't do an input in a sleeping scheduler--but as you noted in your code that's not the best way to do it anyway; an InterruptPort would be the best option there...] Chris

#3 kingpin2k

kingpin2k

    Member

  • Members
  • PipPip
  • 23 posts
  • LocationUSA

Posted 15 August 2010 - 03:13 PM

That's a nice scheduler framework. Wow. Didn't you just get your Netduino? :)

One thing I should bring up...It's perfectly fine to run your code in loop on a Netduino, but .NET Micro Framework is designed to go into "low power" mode when all threads are asleep. So if you put together a scheduler that called Thread.Sleep(##ms) between scheduled events, you'd have a battery-friendly scheduler.

As we work on the power management code in future Netduino firmware releases, this will become more and more beneficial. [Of course, you couldn't do an input in a sleeping scheduler--but as you noted in your code that's not the best way to do it anyway; an InterruptPort would be the best option there...]

Chris



Friday afternoon. That does bring up the question I keep meaning to ask. Could you expound a bit on the netduino's event driven architecture? Is there a specific amount of threads running? Are they doing certain tasks? There aren't mutexes in the .net micro architecture, but I do see we have the ability to lock a code block. Time to go rewrite the scheduler and make it thread safe. That's pretty cool that it has a LPM.
Homer: [Meeting Aliens] Please don't eat me! I have a wife and kids. Eat them!

#4 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 15 August 2010 - 04:17 PM

Friday afternoon. That does bring up the question I keep meaning to ask. Could you expound a bit on the netduino's event driven architecture? Is there a specific amount of threads running? Are they doing certain tasks? There aren't mutexes in the .net micro architecture, but I do see we have the ability to lock a code block. Time to go rewrite the scheduler and make it thread safe. That's pretty cool that it has a LPM.


.NET Micro Framework is a cooperatively-multitasked runtime and the threads are virtual. The threads are very lightweight, so creating a few won't hurt anything. Just be sure to do very small tasks on your threads if you have time-sensitive code in your project (as cooperative multitasking allows up to 20ms timeslices max per thread).

Chris

#5 kingpin2k

kingpin2k

    Member

  • Members
  • PipPip
  • 23 posts
  • LocationUSA

Posted 15 August 2010 - 06:05 PM

Interesting, now I have to decide how I want the scheduler implemented, polling or timer based. So many decision. Until then I've uploaded an event driven scheduler that's being controlled by timers. Attached at the top.
Homer: [Meeting Aliens] Please don't eat me! I have a wife and kids. Eat them!

#6 Snipehunter

Snipehunter

    New Member

  • Members
  • Pip
  • 6 posts

Posted 16 August 2010 - 03:14 AM

Wow, this is rad! This is a great starting framework for a birthday gift idea I had this morning (I'm going to haunt the dollhouse of a friend's daughter as a birthday gift ;) ). Assuming I actually get what I'm looking at, it seems like your scheduler framework takes care of like half the heavy lifting I was looking at for this thing. I'll let you know how it turns out! :D

#7 Omar (OZ)

Omar (OZ)

    Advanced Member

  • Members
  • PipPipPip
  • 564 posts

Posted 16 August 2010 - 04:06 AM

I am working on making a user-friendly class for everything that has to do with the netduino. Like what you did with the Digital Output. But I got some tricks that will make everything very nice, maybe you'll like mine more than yours when I am done. just trying to help, no smartbuttness intended.

#8 kingpin2k

kingpin2k

    Member

  • Members
  • PipPip
  • 23 posts
  • LocationUSA

Posted 16 August 2010 - 04:40 AM

Very possible, I was actually just giving examples of actions :) It's all about time, if you've got time to make some really souped up stuff I'm all bout it.
Homer: [Meeting Aliens] Please don't eat me! I have a wife and kids. Eat them!

#9 Omar (OZ)

Omar (OZ)

    Advanced Member

  • Members
  • PipPipPip
  • 564 posts

Posted 16 August 2010 - 05:15 AM

Very possible, I was actually just giving examples of actions :) It's all about time, if you've got time to make some really souped up stuff I'm all bout it.

Thanks, I do love your code action scheduler. I would have never thought of doing something like that.

#10 mrxer

mrxer

    Advanced Member

  • Members
  • PipPipPip
  • 54 posts
  • LocationAustralia

Posted 16 December 2012 - 01:10 PM

I love the scheduler class bt how do i schedule a atask by date\time instead of milliseconds?

tony


#11 kingpin2k

kingpin2k

    Member

  • Members
  • PipPip
  • 23 posts
  • LocationUSA

Posted 16 December 2012 - 06:06 PM

I love the scheduler class bt how do i schedule a atask by date\time instead of milliseconds?


You could just figure out the milliseconds using timespan and send that in, (or you could keep reading below)
    // first find out what time it is now
    DateTime current_dt = DateTime.Now;
    // second create some time in the future you'd like to execute
    DateTime when_you_want_to_execute = DateTime.Now.AddMinutes(30); 
    // Use timespan to find the difference between the two date time objects
    TimeSpan timespan = when_you_want_to_execute - current_dt;
    // divide the total ticks of the timespan by how many ticks per millisecond
    // to get how many milliseconds should lapse between now and then
    // and then you can just send in how many milliseconds before you want to execute
    long millisecond_difference = timespan.Ticks / TimeSpan.TicksPerMillisecond;
            
    scheduler.ScheduleTask(millisecond_difference, ledOn, ExecutionEventMode.DontInformJustExecute); //turn the light on

That being said, I just threw in two more methods, and I'll update the solution up top there. Just be wary, that DateTime is relative. So if you set up some datetime 3 second in the future, but you don't schedule it for 5 seconds, you will be trying to schedule it in -2 seconds. If I see a negative number I change it to 0, and it will be executed immediately. Best of luck

//Schedule an event using a datetime object
   DateTime when_you_want_to_execute = DateTime.Now.AddSeconds(5); //Some DateTime in the future
   scheduler.ScheduleTask(when_you_want_to_execute, new DebugAction("Try out Date Time."), ExecutionEventMode.DontInformJustExecute);

Homer: [Meeting Aliens] Please don't eat me! I have a wife and kids. Eat them!

#12 Fahdil

Fahdil

    Advanced Member

  • Members
  • PipPipPip
  • 59 posts
  • LocationJakarta, Indonesia

Posted 28 January 2014 - 05:54 AM

it's cool... hmm how if you want to callback action daily at 00:05 AM?

 

i just wonder to use

system.thread.timertimer _timer = new timer(callbackAction, Timespan.Zero, new Timespan(1,0,5,0)); 

but then I realize that, If i start this code on 3pm, then it will execute every 3pm instead 00:05 Am....

 

very appreciate any solution.

 

cheers



#13 Giuliano

Giuliano

    Advanced Member

  • Members
  • PipPipPip
  • 361 posts
  • LocationSimi Valley, CA

Posted 28 January 2014 - 11:55 PM

I have some code to accomplish this at home. I'll share it either tonight or tomorrow night.



#14 Fahdil

Fahdil

    Advanced Member

  • Members
  • PipPipPip
  • 59 posts
  • LocationJakarta, Indonesia

Posted 29 January 2014 - 09:44 AM

Hi Giuliano de medicci...

 

share me please... hihi :P ... now I'm using standard loop by using RTC 

int currentday = 0;int today = datetime.day;while (true){if (today != currentday) // for daily action{   action;}currentday == today;if (datetime.minutes %10 > 0) //this for 10 minutes schdule.no worries to rplace it by using timer/timespan{    recordData;}else{    postData;  // this action takes about 10 - 15 secs. so I waste the rest of minutes = 10}}

so it will execute the action every day at the change of the day.

 

but if there's another way to using timer and timespan, i would love it...  :P bcoz I've using so many "if else" on the loop... 

 

cheers






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.