rt-net / jetsonnanomouse Goto Github PK
View Code? Open in Web Editor NEWLinux device driver of Jetson Nano Mouse
Home Page: https://rt-net.jp/products/jetson-nano-mouse/
License: GNU General Public License v2.0
Linux device driver of Jetson Nano Mouse
Home Page: https://rt-net.jp/products/jetson-nano-mouse/
License: GNU General Public License v2.0
モータドライバへのPWMを出力するIC(左右でそれぞれ1つ)のクロックのソースを内蔵クロックとしているため、左右のモータの回転数差が生じる場合があります。
sample/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
Line 14 in 15dd315
特に理由がなければgpioLED0
→ GPIO_LED0
のように変更してください。
Lines 19 to 32 in 15dd315
Line 40 in 15dd315
Line 62 in 15dd315
Line 137 in 15dd315
細かいうえに影響のない指摘ですが、気になったので。
Line 1111 in 15dd315
Line 665 in 15dd315
似たようなコメントアウトが複数ヶ所にありますが、残したままにしますか?
Lines 1756 to 1759 in 15dd315
Line 11 in 15dd315
Line 15 in 15dd315
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.