View unanswered posts | View active topics It is currently Wed Feb 19, 2020 9:11 am

Reply to topic  [ 2 posts ] 
NXTBee NXT programming problem 
Author Message

Joined: Sun Oct 21, 2012 4:13 pm
Posts: 1
Post NXTBee NXT programming problem
Hello I'm having problem with compiling my program as an error for nxtReadRawHS is coming up. I am a novice when it comes to programming.

Code starts here:

#pragma platform(NXT)

int power = 0; // Global variable for power.
int steer = 0; // Global variable for steering.

void setupHighSpeedLink()
// Initialize port S4 to “high speed” mode.
nxtHS_Mode = hsMsgModeMaster;
void ReadResponse()
byte BytesRead[3]; // Array we’ll be reading into.
nxtReadRawHS(BytesRead[0], 3); // Read the array.

if(BytesRead[0] == '/') { // If we catch the null, read the next three things.
power = BytesRead[1]-70; // -70 is left, 70 is right
steer = BytesRead[2]-100; // -100 is Back, 100 is forward
//direc = BytesRead[3]; // “0? is forward, “1? is reverse.

task main()
bNxtLCDStatusDisplay = true; // Enable top status line display
//Setup the link to be a high-speed link.
bFloatDuringInactiveMotorPWM = true; // The motors WILL coast when power is not appli
//int motorpower = 0; // Variable holds the power.
//The test will continue until an error occurs or
//the enter button on the brick is pressed.
while(nNxtButtonPressed != kEnterButton)
wait1Msec(MS_TO_DELAY); // Put in place to not overload the system.
ReadResponse(); // Check the steering, power, and direction.
// Direction and power.
//if(direc == 0){
// motorpower = power;
// motorpower = power*-1;
motor[motorA] = steer;
motor[motorB] = power;
motor[motorC] = power;
// Change Course
//int steer_posn = steer; // Steer Posn is going to be between -90 and 90
//int rx_posn = nMotorEncoder[motorB]; // This is where our motor posn is right now.
//int tx_posn = steer_posn; // Set the target for Motor Encoder of Motor B to 360.
//if(tx_posn > rx_posn){
// motor[mosteer = (tx_posn-rx_posn)/2;
// nMotorEncoderTarget[motorB] = rx_posn - tx_posn;
//if(tx_posn < rx_posn){
// motor[motorB] = (tx_posn - rx_posn)/2;
// nMotorEncoderTarget[motorB] = tx_posn - rx_posn;
//if(tx_posn > rx_posn){
// motor[motorC] = (tx_posn-rx_posn)/2;
// nMotorEncoderTarget[motorC] = rx_posn - tx_posn;
//if(tx_posn < rx_posn){
// motor[motorC] = (tx_posn - rx_posn)/2;
// nMotorEncoderTarget[motorC] = tx_posn - rx_posn;
//string steer_posn_str;
//StringFormat(steer_posn_str, "%3d", steer_posn);

Just wondering if anyone could help me please.

Sun Oct 21, 2012 4:24 pm

Joined: Tue Feb 28, 2012 3:10 pm
Posts: 197
Post Re: NXTBee NXT programming problem
2 questions;

   nxtReadRawHS(BytesRead[0], 3); // Read the array.

   if(BytesRead[0] == '/') { // If we catch the null, read the next three things.

on the first line, I'll admit, I get so turned around by what is and is not correct on pointers (and is a prime reason pointers are a bad thing and left behind for the most part) - but that looks to me like it would interpret the VALUE of bytesread[0] as an address - that is probably not a good thing. I think you want either BytesRead or &bytesRead[0].

Secondly, character '/' is not a null, so as long as you are sending it as a terminator/delimiter, the code is fine, just that the comment does not match up. General convention is to send a 0x02 - start of transmission STX (actually a 0x10 and a 0x02 DLE-STX), but by no means a requirement (and end it with a 0x10 and 0x03 DLE-ETX, this help re-synchronize when bytes get dropped, a hint for future reference).

edit; BTW - as a novice programmer, I have seen far worse code from professionals - keep it up!

Mike aka Spiked3

Sun Oct 21, 2012 6:15 pm
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

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.