LoginSignup
0
0

More than 5 years have passed since last update.

TOPPERS活用アイデア・アプリケーション開発コンテスト受賞作品紹介(14)第六回(2016)がじぇるねIoTクラス 銀賞&がじぇるね賞 複数タスクを使ったわかりやすいモータ制御 有馬明日香(個人)

Last updated at Posted at 2018-06-24

TOPPERS「活用アイデア」・「アプリケーション開発」コンテスト
は、2011年から毎年実施されています。
https://www.toppers.jp/contest.html

「アプケーション開発」は、ソースコードの公開を前提としています。
「活用アイデア」でも、その後実現したソースコードなどもある。探しながら紹介。

なお、この記事は、TOPPERSプロジェクトの公式見解ではなく、
小川清 の 技術者個人の考えに基づいています。

目的(purpose)

TOPPERS開発アイデア・アプリケーション開発コンテスト受賞作品には、良質な算譜、技術的に崇高な志向、目的を達成するための意思などが感じられる。広く、source codeを表示して紹介し、次の応募作品を促す。

成果(outcome)

応募作品の算譜を眺めると、その技術者の得意分野や技法を感じることができる。応募作品のソースコードを使ってみようという気になる。ソースコードを一度コンパイルしたくなる。自分も良い作品を作ろうという気になる。

TOPPERS活用アイデア・アプリケーション開発コンテスト受賞作品紹介(14)第六回(2016)がじぇるねIoTクラス 銀賞&がじぇるね賞

複数タスクを使ったわかりやすいモータ制御 有馬明日香(個人)

応募資料(application material)等

コンテスト応募資料
https://www.toppers.jp/docs/contest/2016/複数タスクを使ったわかりやすいモータ制御.pdf

Download

ソースコード
https://www.toppers.jp/docs/contest/2016/src_複数タスクを使ったわかりやすいモータ制御.zip

関連資料(related URL)

算譜(source code)

#include <kernel.h>
#include <t_syslog.h>
#include <t_stdlib.h>
#include "syssvc/serial.h"
#include "syssvc/syslog.h"
#include "kernel_cfg.h"

#include "arduino_app.h"
#include "arduino_main.h"

/* GR-PEACH Sketch Template V1.00 */
#include <Arduino.h>

#define MotorPin1 20
#define MotorPin2 21
#define ChangeSpWidth 1
#define ChangePerSec 2
#define OnePlacePin 51
#define TenPlacePin 50

int motor_sp = 60;
int rot_sp = 20;

const int d_in_photo = 52;
int start_msec = millis();
int current_val = 0;
int cnt = 0;
int current_cnt = 0;
int loop2_cnt = 0;

int place_pin[2] = {TenPlacePin,OnePlacePin};
int place_pin_val[2][2] = {{0,1},{1,0}};
int seg_pin[7] = {38,39,41,43,37,40,42};
int seg_val[10][7] = {{0,0,0,0,0,0,1},
                    {1,0,0,1,1,1,1},
                    {0,0,1,0,0,1,0},
                    {0,0,0,0,1,1,0},
                    {1,0,0,1,1,0,0},
                    {0,1,0,0,1,0,0},
                    {0,1,0,0,0,0,0},
                    {0,0,0,1,1,1,1},
                    {0,0,0,0,0,0,0},
                    {0,0,0,0,1,0,0}};

void setup()
{

    pinMode(MotorPin1,OUTPUT);
    pinMode(MotorPin2,OUTPUT);
    pinMode(d_in_photo, INPUT);
    for(int i=0;i<7;i++){
    pinMode(seg_pin[i],OUTPUT);
    }
    pinMode(OnePlacePin,OUTPUT);
    pinMode(TenPlacePin,OUTPUT);
    Serial.begin(115200);

}

/*
 *  7セグメントを光らせるための関数
 */
void seg_digital_write(int seg_val_num,int place_num){

    for(int i=0;i<7;i++){
        digitalWrite(seg_pin[i],seg_val[seg_val_num][i]);
    }
    for(int j=0;j<2;j++){
        digitalWrite(place_pin[j],place_pin_val[place_num][j]);
    }
}


/*
 *  モータを動かす
 */
void loop()
{

    analogWrite(MotorPin1,motor_sp);
    digitalWrite(MotorPin2,LOW);

}

/*
 *  フォトインタラプタで信号を検出し回転数を求める
 */
void loop1(){
    int val = digitalRead(d_in_photo);
    start_msec++;
    if(val != current_val){
        current_val = val;
        cnt++;
    }
    if((millis()-start_msec) > 1000){
        cnt = cnt/2;
        Serial.println(cnt);
        start_msec = millis();
        current_cnt = cnt;
        cnt = 0;
        loop2_cnt = 0;
    }
    delay(1);
}


/*
 *  モータの速度を制御する
 */
void loop2(){
    if(loop2_cnt < ChangePerSec){
   if(current_cnt != 0){
    if(rot_sp > current_cnt-2){
        Serial.println(">");
        motor_sp+=ChangeSpWidth;
    }else if(rot_sp < current_cnt+2){
        Serial.println("<");
        motor_sp-=ChangeSpWidth;
    }else{
        Serial.println("=");
    }
    loop2_cnt++;
   }
    }
    dly_tsk(1);
}

/*
 *  7セグメントに回転数を表示する
 */
void loop3(){
    seg_digital_write(current_cnt%10,0);
    delay(1);
    seg_digital_write(current_cnt/10,1);    
    delay(1);
}
/*
 *  Cyclic Handler
 * 
 *  This handler is called every 10 [ms] as specified in
 *  multitask_arduino.cfg.
 */
void cyclic_handler(intptr_t exinf) {
    irot_rdq(LOOP_PRI); /* change the running loop. */
}

参考資料(reference)

「TOPPERS活用アイデア・アプリケーション開発コンテスト受賞作品紹介」まとめ
https://qiita.com/kaizen_nagoya/items/72b882d96b2841f25faf

TOPPERS活用アイデア・アプリケーション開発コンテストを振り返る
https://researchmap.jp/joxkbxlck-1778110/
「応募すると何が嬉しい」TOPPERS活用アイデア・ アプリケーション開発コンテスト
https://www.slideshare.net/kaizenjapan/ss-78528931

「TOPPERS活用アイデア・アプリケーション開発コンテスト」への道

文書履歴(document history)

ver. 0.10 初稿 20180624

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0