Page 207 - PDA Robotics Using Your Personal Digital Assistant to Control Your Robot
P. 207
PDA 09 5/27/03 8:50 AM Page 183
}
// Chapter 9 / PDA Robot Software for Pocket PC 2002
// Test the connection to make sure all is good. If not
// then display an error
//
char err_buff[10];
int ret = send( Infrared_Socket, (const char *) "o\n",3, MSG_DONTROUTE);
if ( ret == SOCKET_ERROR)
{
int last_error = WSAGetLastError();
_itoa(last_error, &err_buff[0], 10);
msg = "Send to socket errror error ";
msg += err_buff;
this->m_status_window.SetWindowText( (LPCTSTR) msg);
return false;
}
return true;
}
Once the connection has been established, users can now send com-
mands to PDA Robot to instruct it to send range data or motion the
motors. The following is the code to send a command to PDA Robot
and to request the range data. Recall from the chapter on programming
the PIC Microcontroller that a signals the electronics to move Motor1
forward. b – Motor1 Reverse. c – Motor1 Stop. d – Motor2 forward. e
– Motor2 Reverse. f – Motor2 Stop. g – request for PDA Robot to send
the range finder data. The range finder sends a value between 0 and
128, representing the distance to the front of the craft. 0 is approxi-
mately 90 cm and 128 is 10 cm from the range finder.
void CPDABotDlg::OnRobotFwd()
{
char err_buff[10];
CString msg = "Forward";
//
// Send the command to PDA Robot
//
int ret = send( Infrared_Socket, (const char *) "be", 2, MSG_DONTROUTE);
if ( ret == SOCKET_ERROR)
{
//
183