Contents

Aaron Klapheck

% PS2 controlled Boe-Bot and virtual car 28-Aug-08
clear, clc, home
fprintf('The date and time: %s \n \n', datestr(now))
The date and time: 29-Aug-2008 12:34:57 
 

Program Information

% Purpose
% The purpose of this program is to set up direct communication to the
% Basic Stamp so MATLAB can receive packets of information sent by the BS2.

% Execution
% How this works is that a serial comunication port is opened and data is
% read from it using the fscanf command. This data is then transfered into
% numerical format where its button values are then interpretated using
% Diagram 1 (see bs2 source code for diagram). These buttons are then
% displayed in words for easy reading. The program below is set to receive
% 500 packets of information, to end the program at any time simply hit the
% start button on the PS2 controller.

% Users
% For those who wish to use this code to send messages of their own the
% following information may prove useful. The parts of this code that would
% change depending on individuals software and hardware setup are
% followed by a marking; marking: **(may need to change)**.

Use PS2 to Move Car

port = 4; % **(may need to change)**

% Start communication to the Boe-Bot.
[message, s] = StartCommunication(port);

message



world = vrworld('vrmount.wrl'); % create world
open(world); % Opened this world so it can be used.
fig = view(world, '-internal'); % view world
vrdrawnow; % redraw world
car = vrnode(world, 'Automobile'); % Create a VRNODE object.
seeing = vrnode(world, 'View1'); % Create a VRNODE object.


y1 = 0.25; %Vertial postion of car. Never changes.
z1 = 6; %Into/Out of screen. Innitial position.
x1 = 3; %Side to side motion. Innitial position.
rotate_ini = -1.57; % Rotation. Innitial position.

pause(2)

seeing.orientation = [1 0 0 -.6];

rows = 2000;

% Receive data and display its meaning.
for x = 1:rows;

% Get button values
[psxThumbL, psxThumbR] = GetPS2Buttons(s);

  switch psxThumbL; % **(may need to change numbers below)**
%      case 11111111; % No button L
%          % disp('No button L')
      case 01111111; % L arrow
          rotate_ini = (rotate_ini + 0.1);
      case 10111111; % down arrow
          theta = (rotate_ini - 1.57);
          z1 = z1 + 0.5*cos(theta);
          x1 = x1 + 0.5*sin(theta);
      case 11011111; % R arrow
          rotate_ini = (rotate_ini - 0.1);
      case 11101111; % Up arrow
          theta = (rotate_ini - 1.57);
          z1 = z1 - 0.5*cos(theta);
          x1 = x1 - 0.5*sin(theta);
 %     case 11111110; % Select
 %         disp('Select')
      case 11110111; % Start
          disp('Start')
          break %Stop receiving information from the BS2.
 %     otherwise % multiple buttons being pressed L
          % disp('multiple buttons being pressed L')
  end % psxThumbL;

%  switch psxThumbR; % **(may need to change numbers below)**
%      case 11111111; % No button R
%          % disp('No button R')
%      case 01111111; % square
%          disp('square')
%      case 10111111; % X
%          disp('X')
%      case 11011111; % circle
%          disp('circle')
%      case 11101111; % triangle
%          disp('triangle')
%      case 11111110; % L2
%          disp('L2')
%      case 11111101; % R2
%          disp('R2')
%      case 11111011; % L1
%          disp('L1')
%      case 11110111; % R1
%          disp('R1')
%      otherwise % multiple buttons being pressed R
          % disp('multiple buttons being pressed R')
%  end %psxThumbR;

   car.translation = [x1 y1 z1]; % Re-position the car.
   car.rotation = [0, 1, 0, rotate_ini]; % Rotate the car.
   seeing.position = [x1 (y1+10) (z1+15)]; % Camera maintain fixed distance from car.
   vrdrawnow; % Redraw scene.

end %x = 1:rows;

disp('Program will now end.')

EndCommunication(s);

close(world); delete(world);
message = 

    'This is your Boe-Bot'

Start
Program will now end.