Page 1 of 2
control robot using other program
Posted:
Tue Feb 23, 2010 10:24 am
by zamlak
i have make the project surveillance mobile robot using the DIY Project(PR23) and the Xbee-pro that have been purchase fron cytron.to control the robot using PC we can use the XCTU program , but can i use other program to control the robot like using VB or JAVA ?
do i need to change the programming at the PIC at the Xbee part.
Re: control robot using other program
Posted:
Tue Feb 23, 2010 2:46 pm
by yonghui
hi,
u can try check the PIC's source code of PR23, which API mode of xbee is used for the communication. then u will know how to write your VB or Java program to communicate with host xbee radio and send data to the destination xbee radio. your VB or Java program will access the serial port of computer to do serial communication with host Xbee.
computer(java/VB software)<---> xbee(host)<------------>xbee(destination)<--->PIC
regards,
yh
Re: control robot using other program
Posted:
Wed Feb 24, 2010 5:06 pm
by zamlak
For your information,I'm using PR23 that i buy from cytron.I also buy starter kit XBEE PRO to communicate between PC and the robot.So i have invent VB window application to replace X-CTU. When we use the VB code , the communication between the skxbee worked well .But when i try to control the robot by sending number 8(forward) to PR23 robot its cannot detect.
The coding for the robot
- CODE: SELECT_ALL_CODE
void wireless_xbee (void)
{
lcd_clr(); // clear the lcd
while(1) // looping forever
{
lcd_goto (0);
if (data[0] == 100) // check if UART start byte is met
{
send_string(" XBEE CONTROL "); // display string
SPEEDL = 200; // set the motor speed
SPEEDR = 200;
while(1)
{
lcd_goto(20);
if (RCREG == '8') // if character '8' is detected, the robot move forward
{
forward();
send_string("FORWARD ");
}
else if (RCREG == '2') // if character '2' is detected, the robot move backward
{
backward();
send_string("BACKWARD ");
}
else if (RCREG == '6') // if character '6' is detected, the robot turn right
{
right();
send_string("TURN RIGHT ");
}
else if (RCREG == '4') // if character '4' is detected, the robot turn left
{
left();
send_string("TURN LEFT ");
}
else if (RCREG == '5') // if character '5' is detected, then stop the robot
{
stop();
send_string("INVALID COMMAND ");
}
else // else then stop the robot
{
stop();
send_string("INVALID COMMAND ");
}
}
}
else send_string("COMMAND");
}
}
Coding for the VB
- CODE: SELECT_ALL_CODE
' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
' DO NOT FORGET: ADD A REFERENCE TO THE ACTIVECOMPORT LIBRARY FROM THE PROJECT->REFERENCE MENU
' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Public lTimerID As Long
Public objComport As ACOMPORTLib.ComPort
Private Sub buttonSubmit_Click()
textReceived = "--->"
objComport.WriteString (textSend)
GetResult
End Sub
Private Sub buttonView_Click()
If FileExists(textLogfile.Text) = True Then
Shell "notepad " + textLogfile.Text, vbNormalFocus
End If
End Sub
Private Sub CheckDTR_Click()
objComport.RaiseDTR (CheckDTR.Value)
GetResult
End Sub
Private Sub CheckRTS_Click()
objComport.RaiseRTS (CheckRTS.Value)
GetResult
End Sub
Public Function FileExists(sFileName As String) As Boolean
FileExists = CBool(Len(Dir$(sFileName))) And CBool(Len(sFileName))
End Function
Private Sub Form_Load()
textSend = "Text"
Set objComport = CreateObject("ActiveXperts.ComPort")
objComport.ComTimeout = 100
For i = 0 To objComport.GetDeviceCount() - 1
comboDevice.AddItem (objComport.GetDevice(i))
Next
comboDevice.AddItem "COM1"
comboDevice.AddItem "COM2"
comboDevice.AddItem "COM3"
comboDevice.AddItem "COM4"
comboDevice.AddItem "COM5"
comboDevice.AddItem "COM6"
comboDevice.AddItem "COM7"
comboDevice.AddItem "COM8"
comboDevice.ListIndex = 0
comboSpeed.AddItem "Default"
comboSpeed.AddItem "110"
comboSpeed.AddItem "300"
comboSpeed.AddItem "600"
comboSpeed.AddItem "1200"
comboSpeed.AddItem "2400"
comboSpeed.AddItem "4800"
comboSpeed.AddItem "9600"
comboSpeed.AddItem "14400"
comboSpeed.AddItem "19200"
comboSpeed.AddItem "38400"
comboSpeed.AddItem "57600"
comboSpeed.AddItem "64000"
comboSpeed.AddItem "115200"
comboSpeed.AddItem "128000"
comboSpeed.AddItem "256000"
comboSpeed.ListIndex = 0
comboHWFlowControl.AddItem "Default"
comboHWFlowControl.AddItem "Disable"
comboHWFlowControl.AddItem "Enable"
comboHWFlowControl.ListIndex = 0
comboSWFlowControl.AddItem "Default"
comboSWFlowControl.AddItem "Disable"
comboSWFlowControl.AddItem "Enable"
comboSWFlowControl.ListIndex = 0
comboDataFormat.AddItem "Default"
comboDataFormat.AddItem "8,n,1"
comboDataFormat.AddItem "7,e,1"
comboDataFormat.ListIndex = 0
textReceived = ""
EnableControls
End Sub
Private Sub buttonOPEN_Click()
objComport.Device = comboDevice.List(comboDevice.ListIndex)
If (comboSpeed.Text = "Default") Then
objComport.BaudRate = 0
Else
objComport.BaudRate = comboSpeed.Text
End If
objComport.LogFile = textLogfile.Text
objComport.HardwareFlowControl = comboHWFlowControl.ListIndex
objComport.SoftwareFlowControl = comboSWFlowControl.ListIndex
If (comboDataFormat.ListIndex = 0) Then
objComport.DataBits = objComport.asDATABITS_DEFAULT
objComport.StopBits = objComport.asSTOPBITS_DEFAULT
objComport.Parity = objComport.asPARITY_DEFAULT
End If
If (comboDataFormat.ListIndex = 1) Then
objComport.DataBits = objComport.asDATABITS_8
objComport.StopBits = objComport.asSTOPBITS_1
objComport.Parity = objComport.asPARITY_NONE
End If
If (comboDataFormat.ListIndex = 2) Then
objComport.DataBits = objComport.asDATABITS_7
objComport.StopBits = objComport.asSTOPBITS_1
objComport.Parity = objComport.asPARITY_EVEN
End If
objComport.Open
GetResult
EnableControls
End Sub
Private Sub buttonClose_Click()
objComport.Close
GetResult
EnableControls
End Sub
Private Sub Form_Unload(Cancel As Integer)
Timer1.Enabled = False
End Sub
Private Sub EnableControls()
Dim bOpened
bOpened = objComport.IsOpened
CheckDTR.Enabled = bOpened
CheckRTS.Enabled = bOpened
checkCTS.Enabled = bOpened
checkDCD.Enabled = bOpened
checkRI.Enabled = bOpened
checkDSR.Enabled = bOpened
buttonOpen.Enabled = bOpened + 1
buttonClose.Enabled = bOpened
buttonSubmit.Enabled = bOpened
Timer1.Enabled = bOpened
End Sub
Private Sub Timer1_Timer()
Dim strString
strString = objComport.ReadString
If (strString <> "") Then
textReceived = textReceived & strString & vbCrLf
End If
checkDCD.Value = Abs(objComport.QueryDCD)
checkCTS.Value = Abs(objComport.QueryCTS)
checkDSR.Value = Abs(objComport.QueryDSR)
checkRI.Value = Abs(objComport.QueryRI)
End Sub
Private Sub GetResult()
If objComport.LastError = 0 Then
textResult.Caption = "SUCCESS"
Else
textResult.Caption = "ERROR " & objComport.LastError & " ( " & objComport.GetErrorDescription(objComport.LastErro r) & " )"
End If
End Sub
Re: control robot using other program
Posted:
Thu Feb 25, 2010 4:57 pm
by sich
zamlak WROTE:When we use the VB code , the communication between the skxbee worked well .But when i try to control the robot by sending number 8(forward) to PR23 robot its cannot detect.
How do u determine that the communication works well between the skxbee? Both connect to computer running your own vb program? Do u mean it cant detect #8 only and it works well with other inputs?
Re: control robot using other program
Posted:
Sun Feb 28, 2010 11:31 pm
by zamlak
sich WROTE:zamlak WROTE:When we use the VB code , the communication between the skxbee worked well .But when i try to control the robot by sending number 8(forward) to PR23 robot its cannot detect.
How do u determine that the communication works well between the skxbee? Both connect to computer running your own vb program? Do u mean it cant detect #8 only and it works well with other inputs?
i already test the vb using the two different pc and Xbee. they can communicate well,the status at the vb show successful and when i transmit some thing (alphabet or number) at the pc the other pc will receive the same thing that i have been transmit .When i place one Xbee at the robot and one at the pc ,the status at the vb show successful but when i try to transmit no 8(move forward) or other number to move the robot, the display at the robot will show invalid command and it sent back to the vb the same error as invalid command. it mean they can communicate each other but the robot do not recognize the command that have been sent.
Re: control robot using other program
Posted:
Mon Mar 01, 2010 11:43 am
by ober
You can try another way to verify the program on mobile robot. Use wire connection, from PC's VB program transmit the command to mobile robot, if this works, it mean the connection from SKXBee to mobile robot might have problem. If this does not work, it mean the program and connection on mobile robot might have problem.
have you check the baudrate? Jumper maybe?
Re: control robot using other program
Posted:
Wed Mar 03, 2010 9:58 am
by zamlak
ober WROTE:You can try another way to verify the program on mobile robot. Use wire connection, from PC's VB program transmit the command to mobile robot, if this works, it mean the connection from SKXBee to mobile robot might have problem. If this does not work, it mean the program and connection on mobile robot might have problem.
have you check the baudrate? Jumper maybe?
i already try, it does not work.
we use 9600 boudrate that have required for robot.
if there are problem with program, why the robot can sent the invalid signal to the vb?
it but just cannot detect the command only.
Re: control robot using other program
Posted:
Wed Mar 03, 2010 4:12 pm
by sich
I quickly scan through your PC program and i find no specific code that determine the invalid command. I guess you only have one part that display error when some unrecognized commands have been received (but i'm not sure, correct me if i'm wrong).
IF that's the case, you can't be sure that your robot has send an 'invalid' command to your PC program and you also can't make assumption that your PC program has detected the 'invalid' command when it displays error message.
Re: control robot using other program
Posted:
Thu Mar 04, 2010 12:18 am
by zamlak
Actually i already put extra coding so that the robot will send back to VB program.
The updated coding:
- CODE: SELECT_ALL_CODE
void wireless_xbee (void)
{
char textReceived;
textReceived==RCREG;
lcd_clr(); // clear the lcd
while(1) // looping forever
{
lcd_goto (0);
if (data[0] == 100) // check if UART start byte is met
{
send_string(" XBEE CONTROL "); // display string
SPEEDL = 200; // set the motor speed
SPEEDR = 200;
while(1)
{
lcd_goto(20);
if (RCREG == '8') // if character '8' is detected, the robot move forward
{
forward();
send_string("FORWARD ");
while(TXIF==0); //only send the new data after the previous data finish sent
TXREG='F';
while(TXIF==0);
TXREG='O';
while(TXIF==0);
TXREG='R';
while(TXIF==0);
TXREG='W';
while(TXIF==0);
TXREG='A';
while(TXIF==0);
TXREG='R';
while(TXIF==0);
TXREG='D';
}
else if (RCREG == '2') // if character '2' is detected, the robot move backward
{
backward();
send_string("BACKWARD ");
while(TXIF==0); //only send the new data after the previous data finish sent
TXREG='B';
while(TXIF==0);
TXREG='A';
while(TXIF==0);
TXREG='C';
while(TXIF==0);
TXREG='K';
while(TXIF==0);
TXREG='W';
while(TXIF==0);
TXREG='A';
while(TXIF==0);
TXREG='R';
while(TXIF==0);
TXREG='D';
}
else if (RCREG == '6') // if character '6' is detected, the robot turn right
{
right();
send_string("TURN RIGHT ");
while(TXIF==0); //only send the new data after the previous data finish sent
TXREG='R';
while(TXIF==0);
TXREG='I';
while(TXIF==0);
TXREG='G';
while(TXIF==0);
TXREG='H';
while(TXIF==0);
TXREG='T';
}
else if (RCREG == '4') // if character '4' is detected, the robot turn left
{
left();
send_string("TURN LEFT ");
while(TXIF==0); //only send the new data after the previous data finish sent
TXREG='L';
while(TXIF==0);
TXREG='E';
while(TXIF==0);
TXREG='F';
while(TXIF==0);
TXREG='T';
}
else if (RCREG == '5') // if character '5' is detected, then stop the robot
{
stop();
send_string("INVALID COMMAND ");
while(TXIF==0); //only send the new data after the previous data finish sent
TXREG='S';
while(TXIF==0);
TXREG='T';
while(TXIF==0);
TXREG='O';
while(TXIF==0);
TXREG='P';
}
else // else then stop the robot
{
stop();
send_string("INVALID COMMAND ");
while(TXIF==0); //only send the new data after the previous data finish sent
TXREG='I';
while(TXIF==0);
TXREG='N';
while(TXIF==0);
TXREG='V';
while(TXIF==0);
TXREG='A';
while(TXIF==0);
TXREG='L';
while(TXIF==0);
TXREG='I';
while(TXIF==0);
TXREG='D';
}
}
}
else send_string("COMMAND");
}
}
So, when we send the character from the vb program, the robot will send the INVALID command back to the VB program.That's mean the robot detect the receive data but does not recognize the input character.So it only assume the character does not match with the RCREG.Can you help me?
Re: control robot using other program
Posted:
Thu Mar 04, 2010 11:32 am
by sich
1. First you do this: textReceived==RCREG;. Then you check if (data[0] == 100). What are the relation between these two? Why data[0] but not textReceived?
2. Did you see the LCD of your robot displays "XBEE CONTROL"? If yes, where you get the value of data[0]?
3. Then you use while(1) after that. That causes the program keep executing the function in else if no command is received. That could mean your robot has received a command that is not defined. But since it's inside a while loop, the program also will keep entering else when nothing is received after that. Another possibility is the robot receives nothing from your PC at all. I'm not sure how you design your VB program. Put delay of 1 or 2 seconds to each if and else if statements so that you won't miss any string displayed on your LCD for debugging purpose.