View unanswered posts | View active topics It is currently Thu Aug 28, 2014 12:03 pm






Reply to topic  [ 134 posts ]  Go to page Previous  1 ... 5, 6, 7, 8, 9  Next
1.45..1.40 public: RS485 connection for M/S-muxing? samples? 
Author Message
Rookie

Joined: Tue Aug 26, 2008 6:53 am
Posts: 13
Post Re: 1.40 public: how to use RS485 connection? code samples?
Tried to make multiple channels available, but bugs in the new code make me go back.

A Little improvement over the last code is where.

One note in this code. HSeed.c is a library that exports 3 functions. This library only allows 1 Task to use it at a time, so without mutexes or Semaphore or something similar.

I am working the time i can to make one that allows multi Taks. I already can pass the token to each NXT but not sending data.

viewtopic.php?p=3092#p3092


Attachments:
teste_ligacao2.c [2.11 KiB]
Downloaded 260 times
teste_ligacao.c [836 Bytes]
Downloaded 254 times
HSpeed.c [4.27 KiB]
Downloaded 256 times

_________________
My sensors and librarys for robotc
http://hng.av.it.pt/~tgoncalves/robotc/cgit.cgi/
Thu Oct 16, 2008 4:22 pm
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post Re: 1.40 public: how to use RS485 connection? code samples?
(edit: see below!)

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Last edited by Ford Prefect on Fri Nov 07, 2008 6:31 pm, edited 2 times in total.



Wed Nov 05, 2008 11:19 am
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post Re: 1.40 public: how to use RS485 connection? code samples?
so, lets see -
my thread opening question was
Ford Prefect wrote:
hello,
where can I find code samples for a fast RS485 connection between 2 nxt for
- controlling 3 motors at the nxt slave
- reading sensor values of the nxt slave (all kinds: motorEncoder, Touch, ultrasonic, lightactive, HTCompass etc.)


My question was NOT just how to make a RS485 connection, but how to use the 2nd nxt as a multiplexer.

So I'm sorry, I actually can't find the code for motor controlling or sensor reading of a 2nd NXT...
could you plz explain it to me? :oops:

what we need is
1 command for motor remote control like SetHSRemoteMotor(nxtID, port, speed)
and
1 command for remote sensor polling like GetHSRemoteSensorValue(nxtID, port, &value)

Everything else should be done by an included header file like #include "RS485_API.h" .

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Last edited by Ford Prefect on Fri Nov 07, 2008 8:39 pm, edited 2 times in total.



Wed Nov 05, 2008 11:24 am
Profile
Rookie

Joined: Tue Aug 26, 2008 6:53 am
Posts: 13
Post Re: 1.40 public: RS485 connection for M/S-muxing? samples?
Sorry. I did not read the first posts of the topic :shock:
Docilio made me a resume and he was just horried at that moment in making a bi directional comunication width 2 NXT.

I have to apologie too because the last code did not work. Or it is my impression or the basic functions to control de the RS485 had side effects not counted. But now I have it working and a simple API to control a remote (ou more remotes) NXT.

HSpeed.c is a API for NXT to NXT communication (no more than 1 task allowed to use)
teste_ligacao.c and teste_ligacao2.c are 2 programs to test the connection. teste_ligacao2.c can serve as an example but do not bother read them.

Remote.c is your RS485_API.h and it uses HSpeed.c to comunicate to the other NXT but i requires to be the unique to use HSpeed funtions (for now).
slave.c is the program to be run in the slave NXT.
master.c is an example program to show how to use the Remote.c

I hope is not too complicated to see how to use these functions....


Attachments:
teste_ligacao2.c [2.27 KiB]
Downloaded 257 times
teste_ligacao.c [846 Bytes]
Downloaded 277 times
HSpeed.c [4.13 KiB]
Downloaded 274 times

_________________
My sensors and librarys for robotc
http://hng.av.it.pt/~tgoncalves/robotc/cgit.cgi/
Fri Nov 07, 2008 6:13 pm
Profile
Rookie

Joined: Tue Aug 26, 2008 6:53 am
Posts: 13
Post Re: 1.40 public: RS485 connection for M/S-muxing? samples?
Only 3 attachements, so i need another post :bigthumb:


Attachments:
master.c [1.13 KiB]
Downloaded 266 times
slave.c [1.94 KiB]
Downloaded 265 times
Remote.c [1 KiB]
Downloaded 266 times

_________________
My sensors and librarys for robotc
http://hng.av.it.pt/~tgoncalves/robotc/cgit.cgi/
Fri Nov 07, 2008 6:13 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3196
Location: Rotterdam, The Netherlands
Post Re: 1.40 public: RS485 connection for M/S-muxing? samples?
Ogait,

Thanks a lot for the code and all the effort you put into writing it!

Regards,
Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Fri Nov 07, 2008 6:21 pm
Profile WWW
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post Re: 1.40 public: RS485 connection for M/S-muxing? samples?
thx a lot for the code!
For reading I still think it's good to publish the files than only to link for download:
Code:
// master.c
////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//                         Remote NXT Control Client Example
//
//  Program to serve as an example to how to use the 'Remote.c' functions
//
// Autor  : Tiago Costa Gonçalves (ogait87)
// Release: 0.0.1
// Date   : 07/11/2008
//
////////////////////////////////////////////////////////////////////////////////////////////////////////
#include "Remote.c"

task main()
{
   // Setup
   string sFriendlyName;
   getFriendlyName(sFriendlyName);
   IAmNXT = sFriendlyName == "HRF2" ? 0 : 1;
   MaxNXT = 2;
   setupHighSpeedLink();

   //
   int other = (IAmNXT+1) % MaxNXT;
   ubyte motor_pos;
   ubyte sensor_value;

   //
   int count = 0;
   while( 1 )
   {
      count++;
      nxtDisplayTextLine(2, "i: %d", count);

      SetHSRemoteMotor( other, 0, 50);
      wait1Msec(500);
      SetHSRemoteMotor( other, 0, 00);
      wait1Msec(500);

      GetHSRemoteEncoderValue( other, 0, motor_pos);
      nxtDisplayTextLine(4, "Motor Pos: %d", motor_pos);

      GetHSRemoteSensorValue( other, 0, sensor_value);
      nxtDisplayTextLine(5, "Sensor Value: %d", sensor_value);
   }
}


Code:
// slave.c
#pragma config(Sensor, S1,     ss,                  sensorTouch)
#pragma config(Motor,  motorA,          aaa,                  tmotorNxtEncoderClosedLoop)
#pragma config(Motor,  motorB,          aab,                  tmotorNxtEncoderClosedLoop)
#pragma config(Motor,  motorC,          aac,                  tmotorNxtEncoderClosedLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//                         Remote NXT Control Client Server
//
//  Task to process a remote controler command
//
// Autor  : Tiago Costa Gonçalves (ogait87)
// Release: 0.0.1
// Date   : 07/11/2008
//
////////////////////////////////////////////////////////////////////////////////////////////////////////
#include "HSpeed.c"

task main()
{
   // Setup
   string sFriendlyName;
   getFriendlyName(sFriendlyName);
   IAmNXT = sFriendlyName == "HRF2" ? 0 : 1;
   MaxNXT = 2;
   setupHighSpeedLink();

   //
   int count=0;
   while( 1 )
   {
      HSpeedRxDataLen = 0;
      while( HSpeedRxDataLen == 0 ) wait1Msec(10);

      count++;
      nxtDisplayTextLine(2, "i: %d Len: %d", count, HSpeedRxDataLen);

      if ( HSpeedRxDataLen == 2 && HSpeedRxData[0] >= 1 && HSpeedRxData[0] <= 3 )
      {
         motor[HSpeedRxData[0]-1] = HSpeedRxData[1];
         nxtDisplayTextLine(4, "M: %d Speed: %d", HSpeedRxData[0]-1, HSpeedRxData[1]);
      }

      if ( HSpeedRxDataLen == 1 && HSpeedRxData[0] >= 4 && HSpeedRxData[0] <= 6 )
      {
         HSpeedSendByte(HSpeedRxHead, nMotorEncoder[HSpeedRxData[0]-4]);
         nxtDisplayTextLine(5, "MPos: %d MPos: %d", (int)HSpeedRxData[0]-4, nMotorEncoder[HSpeedRxData[0]-4]);
      }

      if ( HSpeedRxDataLen == 1 && HSpeedRxData[0] >= 7 && HSpeedRxData[0] <= 10 )
      {
         HSpeedSendByte(HSpeedRxHead, SensorValue[HSpeedRxData[0]-7]);
         nxtDisplayTextLine(6, "SP: %d Value: %d", (int)HSpeedRxData[0]-7, SensorValue[HSpeedRxData[0]-7]);
      }
   }
}




Code:
// remote.c
////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//                         Remote NXT Control API
//
//  Functions to control a remote NXT
//
// Autor  : Tiago Costa Gonçalves (ogait87)
// Release: 0.0.1
// Date   : 07/11/2008
//
////////////////////////////////////////////////////////////////////////////////////////////////////////
#include "HSpeed.c"

void SetHSRemoteMotor(ubyte remote, ubyte motor, ubyte speed)
{
   HSpeedSendByte(remote, 1 + 0*3 + motor, speed);
}

void GetHSRemoteEncoderValue(ubyte remote, ubyte motor, ubyte &pos)
{
   HSpeedSendByte(remote, 1 + 1*3 + motor);
   HSpeedRxDataLen = 0;
   while( HSpeedRxDataLen == 0 ) wait1Msec(10);
   pos = HSpeedRxData;
   HSpeedRxDataLen = 0;
}

void GetHSRemoteSensorValue(ubyte remote, ubyte sensorPort, ubyte &value)
{
   HSpeedSendByte(remote, 1 + 2*3 + sensorPort);
   HSpeedRxDataLen = 0;
   while( HSpeedRxDataLen == 0 ) wait1Msec(10);
   value = HSpeedRxData;
   HSpeedRxDataLen = 0;
}


Code:
// highspeed.c
////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//                         Port S4 High-Speed RS-485 Full Duplex Token Ring
//
// Autor  : Tiago Costa Gonçalves (ogait87)
// Release: 0.0.6
// Date   : 07/11/2008
//
////////////////////////////////////////////////////////////////////////////////////////////////////////

//#define HSPEED_DEBUG

#ifndef __HSPEED_C__
#define __HSPEED_C__

#ifndef HSPEED_TIMEOUT_BASE
#define HSPEED_TIMEOUT_BASE 1000
#endif

#ifndef HSPEED_TIMEOUT_RAND
#define HSPEED_TIMEOUT_RAND 1000
#endif

//
// Public
//
int  MaxNXT = 1;
int  IAmNXT = 0;

ubyte HSpeedRxHead[1];
ubyte HSpeedRxData[16];
ubyte HSpeedRxDataLen = 0;

task HSpeed;

void setupHighSpeedLink();

void HSpeedSendByte(ubyte destino, ubyte data);
void HSpeedSendByte(ubyte destino, ubyte data_a, ubyte data_b);
void HSpeedSendByte(ubyte destino, ubyte data_a, ubyte data_b, ubyte data_c);

/////////////////////////////////////////////////////////////////////////////////////////
//                                     Private
/////////////////////////////////////////////////////////////////////////////////////////
ubyte HSpeedTxData[1+16];
ubyte HSpeedTxLen = 0;

ubyte chr[16];

void setupHighSpeedLink()
{
   nxtEnableHSPort();
   //nxtSetHSBaudRate();
   nxtHS_Mode = hsMsgModeMaster ;
   nxtHS_Mode = hsRawMode;

   StartTask(HSpeed);

   return;
}

void HSpeedSendByte(ubyte destino, ubyte data)
{
   while(HSpeedTxLen != 0)
      EndTimeSlice();

   HSpeedTxData[0] = (IAmNXT << 6) | (destino << 4) | 1;
   HSpeedTxData[1] = data;
   HSpeedTxLen     = 1;
}

void HSpeedSendByte(ubyte destino, ubyte data_a, ubyte data_b)
{
   while(HSpeedTxLen != 0)
      EndTimeSlice();

   HSpeedTxData[0] = (IAmNXT << 6) | (destino << 4) | 2;
   HSpeedTxData[1] = data_a;
   HSpeedTxData[2] = data_b;
   HSpeedTxLen     = 2;
}

void HSpeedSendByte(ubyte destino, ubyte data_a, ubyte data_b, ubyte data_c)
{
   while(HSpeedTxLen != 0)
      EndTimeSlice();

   HSpeedTxData[0] = (IAmNXT << 6) | (destino << 4) | 3;
   HSpeedTxData[1] = data_a;
   HSpeedTxData[2] = data_b;
   HSpeedTxData[3] = data_c;
   HSpeedTxLen     = 3;
}

void HSpeedMaster()
{
#ifdef HSPEED_DEBUG
   static int master_count = 0;
   master_count++;
   nxtDisplayTextLine(6, "MASTER: %d", master_count);
#endif

   if ( HSpeedTxLen > 0)
   {
      nxtWriteRawHS(HSpeedTxData, 1+HSpeedTxLen, 0);
      HSpeedTxLen = 0;
   }
   else
   {
      nxtWriteRawHS((IAmNXT << 6), 1, 0);
   }
}

bool HSpeed_ReadRawHS(int n)
{
   int i, timeout = HSPEED_TIMEOUT_BASE + random[HSPEED_TIMEOUT_RAND];

   ClearTimer(T1);
   for(i=0; i<n; )
   {
      i += nxtReadRawHS(chr[i], n-i);
      if ( time1[T1] >= timeout )
      {
         return false;
      }
   }

   return true;
}

task  HSpeed()
{
   int senderID, reciverID, length;

#ifdef HSPEED_DEBUG
   int head_count = 0;
   int loop_count = 0;
   int timeout_count = 0;
#endif

   if ( IAmNXT == 0 )   // So start roling the comunication
   {
      HSpeedMaster();
   }

   while(true)
   {
#ifdef HSPEED_DEBUG
      loop_count++;
        nxtDisplayTextLine(3, "LOOP: %d", loop_count);
#endif

      // Receve 1 byte, the header
      if ( !HSpeed_ReadRawHS(1) )
      {
#ifdef HSPEED_DEBUG
         timeout_count++;
         nxtDisplayTextLine(7, "TIMEOUT1: %d", timeout_count);
#endif
         HSpeedMaster(); // so be me now :)
         continue;
      }

      // Get Head fields
      senderID  = (chr[0] >> 6) & 0x3;
      reciverID = (chr[0] >> 4) & 0x3;
      length    = (chr[0] >> 0) & 0xF;

#ifdef HSPEED_DEBUG
      nxtDisplayTextLine(4, "SRC:%d DEST:%d", senderID, reciverID);
      head_count++;
      nxtDisplayTextLine(5, "LEN: %d COUNT: %d", length, head_count);
#endif

      if ( length > 0 )
      {
         if ( !HSpeed_ReadRawHS(length) )
         {
#ifdef HSPEED_DEBUG
            timeout_count++;
            nxtDisplayTextLine(7, "TIMEOUT2: %d", timeout_count);
#endif
            HSpeedMaster(); // so be me now :)
            continue;
         }

         if ( reciverID == IAmNXT )
         {
            HSpeedRxHead[0] = senderID;
            memcpy(HSpeedRxData, chr, length);
            HSpeedRxDataLen = length;
         }
      }

      // I am the next NXT to transmit?
      if ( (senderID + 1) % MaxNXT == IAmNXT )
      {
         HSpeedMaster();
      }
   }
}

#endif



Last edited by Ford Prefect on Fri Nov 07, 2008 8:04 pm, edited 1 time in total.



Fri Nov 07, 2008 6:24 pm
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post Re: 1.40 public: RS485 connection for M/S-muxing? samples?
(...continuing...)
Code:
// teste_ligacao.c
////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//                         Port S4 High-Speed RS-485 Full Duplex Token Ring Tester
//
//  Program to test the code
//
// Autor  : Tiago Costa Gonçalves (ogait87)
// Release: 0.0.2
// Date   : 07/11/2008
//
////////////////////////////////////////////////////////////////////////////////////////////////////////

#define HSPEED_DEBUG

#include "HSpeed.c"

task main()
{
   // Setup
   string sFriendlyName;
   getFriendlyName(sFriendlyName);
   IAmNXT = sFriendlyName == "HRF2" ? 0 : 1;
   MaxNXT = 2;
   setupHighSpeedLink();

   //
   eraseDisplay();
   bNxtLCDStatusDisplay = true; // Enable top status line display

   nxtDisplayTextLine(2, "IAmNXT: %d MAX: %d", IAmNXT, MaxNXT);

   while(true)
   {
      wait1Msec(10);
   }
}



Code:
// test_ligacao2.c
////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//                         Port S4 High-Speed RS-485 Full Duplex Token Ring Tester
//
//  Program to test the efficiency of the HSpeed Connection
//
// Autor  : Tiago Costa Gonçalves (ogait87)
// Release: 0.0.2
// Date   : 07/11/2008
//
////////////////////////////////////////////////////////////////////////////////////////////////////////
#define HSPEED_TIMEOUT_BASE 10000
//#define HSPEED_DEBUG

#include "HSpeed.c"

////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//                                        recieve Data
//
////////////////////////////////////////////////////////////////////////////////////////////////////////
void recieve()
{
   int counta = 0;

   while(true)
   {
      if( HSpeedRxDataLen != 0  )
      {
         counta++;
         nxtDisplayTextLine(6, "Rx: ID %d Len %d", HSpeedRxHead[0]     , HSpeedRxDataLen);
         nxtDisplayTextLine(7, "Rx: %d %d"       , (int)HSpeedRxData[0], counta          );
         HSpeedRxDataLen = 0;
      }
   }
}
////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//                                        send Data
//
////////////////////////////////////////////////////////////////////////////////////////////////////////
void send()
{
   int count = 0;

   ClearTimer(T2);
   while(true)
   {
      if( time1[T2] > 20 )
      {
         count++;
         HSpeedSendByte( (IAmNXT+1) % MaxNXT, count);
         nxtDisplayTextLine(4, "Send: %d", count);
         ClearTimer(T2);
      }
   }
}

////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//                                        Main Task
//
////////////////////////////////////////////////////////////////////////////////////////////////////////
task main()
{
   // Setup
   string sFriendlyName;
   getFriendlyName(sFriendlyName);
   IAmNXT = sFriendlyName == "HRF2" ? 0 : 1;
   MaxNXT = 2;
   setupHighSpeedLink();

   //
   eraseDisplay();
   bNxtLCDStatusDisplay = true; // Enable top status line display

   nxtDisplayTextLine(2, "IAmNXT: %d MAX: %d", IAmNXT, MaxNXT);

   if ( IAmNXT == 0 )
   {
      send();
   }
   else
   {
      recieve();
   }
}

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Last edited by Ford Prefect on Fri Nov 07, 2008 8:04 pm, edited 1 time in total.



Fri Nov 07, 2008 6:32 pm
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post Re: 1.40 public: RS485 connection for M/S-muxing? samples?
man, what a program! :eek:
I guess I need some days even to test this.

Great job! Congratulations!

Image

Nominated for the first RobotC Improvement Emmy Award! :bigthumb:
Image

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Last edited by Ford Prefect on Fri Nov 07, 2008 7:08 pm, edited 2 times in total.



Fri Nov 07, 2008 6:39 pm
Profile
Rookie

Joined: Tue Aug 26, 2008 6:53 am
Posts: 13
Post Re: 1.40 public: RS485 connection for M/S-muxing? samples?
Thanks :D

I think it is easy to use this.

1º Put HSpeed.c Remote.c slave.c master.c in the same dir
2º Give a name to each NXT
3º Change in slave.c and master.c "HRF2" to the the name of the Master NXT (the one that is going to control de other)
4º Download slave.c to the NXT to be controlled and connect a motor in port A and a push sensor in sensor port 1.
5º Download master.c to the NXT to be the controller.
6º Do not forget to connect both sensor port 4
7º Start the slave program and then the master program in the other NXT
8º Enjoy

_________________
My sensors and librarys for robotc
http://hng.av.it.pt/~tgoncalves/robotc/cgit.cgi/


Fri Nov 07, 2008 6:58 pm
Profile
Expert

Joined: Sun Sep 09, 2007 10:12 am
Posts: 116
Post Re: 1.40 public: RS485 connection for M/S-muxing? samples?
That's my friend !!!

I think that this code is fine. It was a good investment giving you an extra NXT :P

I wil test it with 4 nxt (i guess i can do it)

_________________
http://www.apcsguarda.com
My Project: http://www.robotc.net/forums/viewtopic.php?f=15&t=712


Fri Nov 07, 2008 7:34 pm
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post Re: 1.40 public: RS485 connection for M/S-muxing? samples?
hi,
I tested you code!
The good news: the motor is going forward in steps each 1/2 second as it should.

But unfortunately the values are not shown correctly at my master's display:
the motor encoder stays all the time at a value of maybe 41272,
and the sensor always shows a value of 413 either if it has been pressd or not.

Have I done something faulty?

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Sat Nov 08, 2008 9:20 am
Profile
Rookie

Joined: Tue Aug 26, 2008 6:53 am
Posts: 13
Post Re: 1.40 public: RS485 connection for M/S-muxing? samples?
For a quick answer i guess it is due to the different compiler version. I was using the 1.40 version of the compiler.

Ether way, that values should never appear since i use ubyte type. Maybe a conversion error? The motor encoder should change by it self but due the way the example master program was build, the touch sensor is only acquired just before the motor starts. Ether way, only 0 or 1 should appear.

Have you made a custom master.c?

_________________
My sensors and librarys for robotc
http://hng.av.it.pt/~tgoncalves/robotc/cgit.cgi/


Sat Nov 08, 2008 10:00 am
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post Re: 1.40 public: RS485 connection for M/S-muxing? samples?
Of course I had only changed the name of my master (simply "002", my slave is "003"), nothing else.
I'm using 1.45

But ubyte always has been a bad choice in RobotC, because in RobotC it doesn't exist any unsigned value at all (although the usage won't suprisingly lead to a compiler error).


So now I changed two code lines by an added "(int)" for value conversion from byte to int:

Code:
  nxtDisplayTextLine(4, "Motor Pos: %d", (int)motor_pos);
  //...
  nxtDisplayTextLine(5, "Sensor Value: %d", (int)sensor_value);


now the values are more credible, at least the touch sensor value now changes between 1/0 when pressed/not pressed.

THAT'S FINE. :D

But consider that the motor encoder indeed is a long (32 bit = 4 byte) integer value. Using BYTE (CHAR) as a return value of this, naturally the values at the master's display jump in a way like
-4
-7
-95
-121
-114
-117
-125
+127
and so on.

so the GetMotorEncoderValue should poll 32 bit integers instead of 1 byte (or ubyte) = 8 bit.

Other sensor values (Light, Compass) have a short integer value as a result (0...1023).
Try it out by changing the attached Sensor from "Touch" to "Sonar".

So I generally would suggest to use
16 bit = 2 byte int as a return value of GetSensorValue
and
32 bit = 4 byte long as a return value of GetMotorEncoderValue

regards,
Helmut

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Sat Nov 08, 2008 10:25 am
Profile
Rookie

Joined: Sat Apr 19, 2008 11:51 am
Posts: 43
Post Re: 1.40 public: RS485 connection for M/S-muxing? samples?
ogait,
many thanks and congratulations from me, too!
As Helmut and I am working on bigger robot projects with many Lego sensors and Lego motors it's a great help for of us.

The reason why your program sometimes hangs when using different tasks for polling and controlling, is now clear: because of missing comm synchronization. As I heard, you're meanwhile working on this issue, too, I'm gladly looking forward to this!

cu
spaceballs


Tue Nov 11, 2008 7:06 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 134 posts ]  Go to page Previous  1 ... 5, 6, 7, 8, 9  Next

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.