RobotC掲示板 8418
RobotCを使っている皆さん、使っていてわからないところがある皆さん、是非ここで情報交換してください!! 因みに、管理者TKのロボブログです。 http://blog.livedoor.jp/tk_robot_drs345/ 又、中傷等のコメントは論外、削除させていただきます。 よろしくお願いいたします。
忘れないうちに! | ■↑▼ |
2014/09/11 (Thu) 12:47:24
少しだけでもいいので時間をください。
給料が少なく、生活が豊かになりませんでした。
人生を変えてくれる人と出会いました。
ものすごい金額を手に入れてしまったんです。
お金はものすごく持ってるみたいです。
実際にお金を受け取ってしまうと、人生は何もかもうまくいくことがわかりました。
是非みてください。
http://hum.thick.jp/
I2C | ■↑▼ |
2011/02/17 (Thu) 21:16:37
どうも。。TKです。。
この掲示板も早速過疎化が進んでたりしますが、よろしくお願いします。。
多分あまりいないとは思うのですが、I2C系のプログラムが分かる方いらっしゃいますか?
RobotCForumを見ても、よくわからないのですが。。
よろしくお願いします。。
2011/06/21 (Tue) 14:36:06
私も少しは、わかりますが1つだけ分からないのは、I2Cアドレスを変える方法です。
どうすればいいですか。
2011/06/23 (Thu) 21:43:16
はじめまして、TKと申します。
I2Cアドレスを変更するプログラムなら、ありますよ。
//////////////////////////////////////////////////////////////////////////////
//
// change the adress of the I2C sensor oldAddresswith the NewAddress
//
/////////////////////////////////////////////////////////////////////////////
void Change_add(byte oldAddress,byte newAddress)
{
byte i2cMsg[8];
const byte kMsgSize = 0;
const byte kDeviceAddress = 1;
const byte kCommandAddress = 2;
const byte kCommand = 3;
nI2CBytesReady[S2] = 0;
SensorType[S2] = sensorI2CMindsensorsDist;
// Build the I2C message
i2cMsg[kMsgSize] = 3;
i2cMsg[kDeviceAddress] = oldAddress ;
i2cMsg[kCommandAddress] =0x41;
i2cMsg[kCommand]=0xA0;
while (nI2CStatus[S2] == STAT_COMM_PENDING); // Wait till I2C bus is ready
sendI2CMsg(S2, i2cMsg[0], 0); // Send the message
wait10Msec(10);
i2cMsg[kCommand]=0xAA;
while (nI2CStatus[S2] == STAT_COMM_PENDING); // Wait till I2C bus is ready
sendI2CMsg(S2, i2cMsg[0], 0); // Send the message
wait10Msec(10);
i2cMsg[kCommand]=0xA5;
while (nI2CStatus[S2] == STAT_COMM_PENDING); // Wait till I2C bus is ready
sendI2CMsg(S2, i2cMsg[0], 0); // Send the message
wait10Msec(10);
i2cMsg[kCommand]=newAddress;
while (nI2CStatus[S2] == STAT_COMM_PENDING); // Wait till I2C bus is ready
sendI2CMsg(S2, i2cMsg[0], 0); // Send the message
wait10Msec(10);
}
//////////////////////////////////////////////////////////////////////////////
//
// demo main function to show change adress function
//
/////////////////////////////////////////////////////////////////////////////
task main()
{
nxtDisplayTextLine(1, "mindsensors.com");
nxtDisplayTextLine(2, "address change");
Change_add(0xa8,0x04);
StopAllTasks();
}
ここの、Change_addに、(今のI2Cアドレス,変更後のI2Cアドレス)
というようにすれば、アドレスが変わります。
2011/06/23 (Thu) 21:45:40
因みに、ポートスプリッター経由でポート一つに複数のセンサーをつけた時に、そのセンサー名とI2Cアドレスを表示させるプログラムもあります。
#define i2cScanVersion 0x00
#define i2cScanDeviceName 0x10
#define i2cScanPort S2 // Connect sensor to this port!!
byte replyMsg[10];
//////////////////////////////////////////////////////////////////////////////
//
// Read the data from I2C sensor
//
/////////////////////////////////////////////////////////////////////////////
byte I2Cscan(byte ScanID )
{
byte i2cscanMsg[4];
const byte MsgSize = 0;
const byte i2cScanAddress = 1;
const byte ReadAddress = 2;
// Build the I2C message
i2cscanMsg[MsgSize] = 2;
i2cscanMsg[i2cScanAddress] = ScanID ;
i2cscanMsg[ReadAddress] =i2cScanDeviceName ;
replyMsg[0]=0x00;
while (nI2CStatus[i2cScanPort] == STAT_COMM_PENDING); // Wait for I2C bus to be ready
sendI2CMsg(i2cScanPort, i2cscanMsg[0], 8); // Send the message
if(nI2CStatus[i2cScanPort] == ERR_COMM_BUS_ERR)return 0;
while (nI2CStatus[i2cScanPort] == STAT_COMM_PENDING); // Wait for I2C bus to be ready
readI2CReply(i2cScanPort, replyMsg[0], 8); // read all the six data bytes
if(replyMsg[0]==0x00) return 0;
return 1;
}
//////////////////////////////////////////////////////////////////////////////
//
// scans the port 1 and Display the results on NXT display
//
/////////////////////////////////////////////////////////////////////////////
task main()
{
int i2cScanID;
ubyte count;
string s2;
string s1;
int r, i;
nI2CBytesReady[i2cScanPort] = 0;
SensorType[i2cScanPort] = sensorI2CCustom9V;
nxtDisplayTextLine(0,"mindsensors.com");
nxtDisplayTextLine(1,"Name: i2cID(hex)");
nxtDisplayTextLine(2,"nothing found?");
i2cScanID = 0x02;
count=1;
while(i2cScanID<0xfe)
{
if(I2Cscan(i2cScanID)==1)
{
count++;
i = 0;
s1 = "";
while ( replyMsg[i] != 0x00 ) {
r = replyMsg[i];
StringFormat (s2, "%s%c", s1, r);
s1 = s2;
i++;
}
StringFormat (s2, "%s: %x", s1, i2cScanID);
nxtDisplayTextLine(count,"%s", s2);
}
i2cScanID += 0x02;
}
wait10Msec(1000);
StopAllTasks();
}
HiTechnic加速度センサー | ■↑▼ |
2011/01/15 (Sat) 16:43:50
管理者TKです。
先日、HiTechnic社の加速度センサーを購入しました。
しかし、プログラムに入った時にセンサーの値を初期化する方法がわかりません。
その様な方法があるかないかもわかりませんが、
それについて何か知っている方は、投稿よろしくお願いします。
2011/01/15 (Sat) 21:40:25
SetSensorType(HTAC,SensorI2CHTCompass)でいけると思います。
2011/01/15 (Sat) 22:43:42
投稿ありがとうございます。一応試してみました。
プログラムは
#pragma config(Sensor, S1, leftrf, sensorReflection)
#pragma config(Sensor, S2, sonar, sensorSONAR)
#pragma config(Sensor, S3, rightrf, sensorReflection)
#pragma config(Sensor, S4, HTAC, sensorI2CHiTechnicAccel)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
#include "drivers/common.h"
#include "drivers/HTAC-driver.h"
task main()
{
SetSensorType(S4,sensorI2CHiTechnicAccel);
int Xaxis = 0;
int Yaxis = 0;
int Zaxis = 0;
while(true)
{
HTACreadX(HTAC,Xaxis);
HTACreadY(HTAC,Yaxis);
HTACreadZ(HTAC,Zaxis);
nxtDisplayTextLine(1,"X == %d",Xaxis);
nxtDisplayTextLine(3,"Y == %d",Yaxis);
nxtDisplayTextLine(5,"Z == %d",Zaxis);
wait1Msec(500);
eraseDisplay();
}
}
こんな感じですが、やはりディスプレイには0でない値が返ってきます。
やはり値を0にする方法は無いのでしょうか。
2011/01/16 (Sun) 12:53:23
あ、もしかしたら初期化の意味誤解されてしまったのかもしれません。
だとしたらすいません。m(_ _)m
2011/05/15 (Sun) 00:29:59
加速度センサは重力加速度の影響があるので、値は0じゃないですよ。
機械的に停止状態時の値をオフセット値として、測定データから減算すれば
いいんじゃない?
2011/06/23 (Thu) 21:35:44
遅れてしまってすいません。TKです。
そうですね。今は加速度センサーは使用していませんが、そのようにしていくべきですね。
ただ、いまだに加速度センサーでの坂検知の方法が分からないのですが・・・。
単語について | ■↑▼ |
2011/01/19 (Wed) 21:27:26
TKです。初めてから早々この掲示板に来て下さる方が増えてきました。皆さん是非遠慮せずにカキコしてくださいね。
さて、そんなわけで、今日はウp主の知らない単語を質問したいと思います。
意味知っている方がいたら是非。
bool ・・・ よくヘッダーファイルで見かけます。
Byte ・・・ これはcファイルでもよく見かけますね。intみたいな位置によくいます。
ex)byte sensor = 0;
tByteArray signalstr; みたいな。
tByteArray ・・・ これまた上同様。
const ・・・ 時々cファイルで。
long ・・・ これまた上同様。
case ・・・ これは一体?てな感じです。
brake ・・・ returnみたいな感じでしょうか。
return ・・・ 「return false」とかよくありますが、何の意味か。
switch ・・・ 普通のC言語と同じ意味でしょうか。
typedef ・・・ はて。これは。「typedef struct」とか、「typedef enum」みたいな感じで見かけます。
まあこんな感じです。よろしくお願いしますm(_ _)m
2011/02/05 (Sat) 20:33:03
しばらくたった間に大分わかるようになったものがあるので、それは解決済みということで、よろしくお願いします。。
bool brake
byte typedef
です。しかし、これ以外の単語は、まだ意味不明状態なのでよろしくお願いします。。
あと、これらの単語についてはブログ上で少しずつ解説をしていきたいと思うので、ブログへも是非。。