Giter Club home page Giter Club logo

jetsonnanomouse's People

Contributors

shotaak avatar tiryoh avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Forkers

tubbz-alt kenitp

jetsonnanomouse's Issues

左右のモータの回転数差の低減

現状の問題点

モータドライバへのPWMを出力するIC(左右でそれぞれ1つ)のクロックのソースを内蔵クロックとしているため、左右のモータの回転数差が生じる場合があります。

sample/step6.cを以下のように変更し実行した結果、以下のようにパルス数がずれることを確認できます。
モータを高速回転させるので試す際は本体を浮かせて試すことを推奨します。また個体によってはもう少し左右でパルス数に差が開くかもしれません。

step6.c
// Copyright 2020 RT Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <unistd.h>

#define FILE_MOTOREN "/dev/rtmotoren0"
#define FILE_MOTOR_L "/dev/rtmotor_raw_l0"
#define FILE_MOTOR_R "/dev/rtmotor_raw_r0"
#define FILE_COUNT_L "/dev/rtcounter_l0"
#define FILE_COUNT_R "/dev/rtcounter_r0"
#define BUFF_SIZE 256

void motor_drive(char *freq_l, char *freq_r) {
    FILE *motor_l, *motor_r;
    if ((motor_l = fopen(FILE_MOTOR_L, "w")) != NULL &&
        (motor_r = fopen(FILE_MOTOR_R, "w")) != NULL) {
        fputs(freq_l, motor_l);
        fputs(freq_r, motor_r);
    }
    fclose(motor_l);
    fclose(motor_r);
}

void delete_newline(char *str) {
    char *p;

    if ((p = strchr(str, '\n')) != NULL) {
        *p = '\0';
    }
}

void print_counter(const int timeout) {
    FILE *count_l, *count_r;
    char buff_l[BUFF_SIZE];
    char buff_r[BUFF_SIZE];

    time_t start = time(NULL);
    int elapsed_time = 0;

    while (elapsed_time < timeout) {
        elapsed_time = (int)(time(NULL) - start);
    }
    if ((count_l = fopen(FILE_COUNT_L, "r")) != NULL &&
        (count_r = fopen(FILE_COUNT_R, "r")) != NULL) {
        while (fgets(buff_l, BUFF_SIZE, count_l) != NULL) {
        }
        while (fgets(buff_r, BUFF_SIZE, count_r) != NULL) {
        }
        delete_newline(buff_l);
        delete_newline(buff_r);
        printf("count_l:%s, count_r:%s\n", buff_l, buff_r);
    }
    fclose(count_l);
    fclose(count_r);
}

void reset_counters_and_motors(void) {
    FILE *count_l, *count_r;

    motor_drive("0", "0");

    printf("Reset counter\n");
    if ((count_l = fopen(FILE_COUNT_L, "w")) != NULL &&
        (count_r = fopen(FILE_COUNT_R, "w")) != NULL) {
        fputs("0", count_l);
        fputs("0", count_r);
    }
    fclose(count_l);
    fclose(count_r);
}

int main(void) {
    int motoren = open("/dev/rtmotoren0", O_WRONLY);
    // int motor_l = open("/dev/rtmotor_raw_l0",O_WRONLY);

    printf("Motor On\n");
    write(motoren, "1", 1);
    reset_counters_and_motors();

    printf("Move forward\n");
    usleep(500 * 1000);
    motor_drive("1200", "1200");
    print_counter(10);
    reset_counters_and_motors();

    printf("Move backward\n");
    usleep(500 * 1000);
    motor_drive("-1200", "-1200");
    print_counter(10);
    reset_counters_and_motors();

    printf("Motor Off\n");
    write(motoren, "0", 1);

    close(motoren);
    return 0;
}

実行結果

Motor On
Reset counter
Move forward
count_l:11460, count_r:11338
Reset counter
Move backward
count_l:11726, count_r:11602
Reset counter
Motor Off

改善案

共通の外部クロックを使うことによる左右のPWMのずれの低減
(2021年春ごろより出荷されている分よりPWMを出力するICに外部クロックが追加されています)

関連: rt-net/JetsonNanoMouse_Hardware#9

代替案

その他

レビュー

rtmouse.c

Jetson Nano → Jetson Nano Mouse

MODULE_DESCRIPTION("A simple driver for control Jetson Nano");

表記の統一

特に理由がなければgpioLED0GPIO_LED0のように変更してください。

#define gpioLED0 13 // PIN22
#define gpioLED1 15 // PIN18
#define gpioLED2 232 // PIN16
#define gpioLED3 79 // PIN16
#define gpioSW0 78 // PIN40
#define gpioSW1 12 // PIN37
#define gpioSW2 77 // PIN38
#define gpioSENR 194 // PIN15
#define gpioSENL 149 // PIN29
#define gpioSENRF 14 // PI13
#define gpioSENLF 50 // PIN11
#define gpioMOTOREN 200 // PIN31
#define gpioMOTORDIRR 168 // PIN32
#define gpioMOTORDIRL 216 // PIN7

REG_GPIO_NAMEが未使用であれば削除

#define REG_GPIO_NAME "Jetson Nano GPIO"

NUM_DEV_CNTが未使用であれば削除

#define NUM_DEV_CNT 1

PCA9685_I2C_ADDRは未使用なので削除

#define PCA9685_I2C_ADDR

コメントの/dev/rtled3 の書き忘れ

細かいうえに影響のない指摘ですが、気になったので。

/* /dev/rtled0,/dev/rtled1,/dev/rtled2 */

値を変えるたびにログが出るので、KERN_DEBUGにしたほうがよい

printk(KERN_INFO "%s: set 0x%x to %d[Hz]\n", DRIVER_NAME, client->addr,

コメントアウトを残す?

似たようなコメントアウトが複数ヶ所にありますが、残したままにしますか?

JetsonNanoMouse/rtmouse.c

Lines 1756 to 1759 in 15dd315

// dev_info->device_major = MAJOR(dev);
// dev = MKDEV(dev_info->device_major, DEV_MINOR);
// printk(KERN_DEBUG "rtbuzzer_i2c major:%d, minor:%d\n",
// dev_info->device_major, DEV_MINOR);

Makefile

Raspberry Pi Mouse → Jetson Nano Mouse

all: ## build the Raspberry Pi Mouse kernel module, rtmouse.ko

@echo "the Raspberry Pi Mouse device driver installer"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.