Matlab connection via the serial port, to control the robot from there (interactively)

Dependencies:   MODSERIAL QEI

Committer:
jbrouwer
Date:
Tue Nov 01 02:36:29 2016 +0000
Revision:
3:4fd668c1dbf5
Parent:
2:5de7be1a34dc
Added example code

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jbrouwer 2:5de7be1a34dc 1 % THIS IS A M FILE
jbrouwer 2:5de7be1a34dc 2
jbrouwer 2:5de7be1a34dc 3 % SPECIFY SERIAL PORT. On windows this is COM1, COM2...
jbrouwer 2:5de7be1a34dc 4 % List serial ports; this=instrhwinfo('serial');
jbrouwer 2:5de7be1a34dc 5 % this.AvailableSerialPorts
jbrouwer 2:5de7be1a34dc 6 clear all;
jbrouwer 2:5de7be1a34dc 7 delete(instrfindall) % this closes the previous connection.
jbrouwer 2:5de7be1a34dc 8 PORT = '/dev/cu.usbmodem1412';
jbrouwer 2:5de7be1a34dc 9
jbrouwer 2:5de7be1a34dc 10 s = serial(PORT);
jbrouwer 2:5de7be1a34dc 11 set(s, 'BAUDRATE', 115200);
jbrouwer 2:5de7be1a34dc 12 set(s, 'TERMINATOR', 'CR/LF');
jbrouwer 2:5de7be1a34dc 13 fopen(s);
jbrouwer 2:5de7be1a34dc 14
jbrouwer 2:5de7be1a34dc 15 while 1
jbrouwer 2:5de7be1a34dc 16 line = fgetl(s);
jbrouwer 2:5de7be1a34dc 17 pulses_in = str2num(line);
jbrouwer 2:5de7be1a34dc 18 send_data = Controller(pulses_in,0);
jbrouwer 2:5de7be1a34dc 19 fprintf(s,strcat(num2str(send_data), '\r\n'));
jbrouwer 2:5de7be1a34dc 20 end