Changeset 100
- Timestamp:
- 06/24/08 17:23:27 (5 years ago)
- Location:
- branches
- Files:
-
- 2 added
- 3 modified
-
atorf/USB_ToolboxTest_Windows/NXT_LSRead.m (modified) (1 diff)
-
behrens/RWTHMindstormsNXT/SendMotorSettings.m (modified) (2 diffs)
-
workshop/Accelerator/AcceleratorTest2_USB.m (added)
-
workshop/Accelerator/AcceleratorTest3_USB.m (added)
-
workshop/Accelerator/GetAccelerator.m (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/atorf/USB_ToolboxTest_Windows/NXT_LSRead.m
r25 r100 169 169 170 170 BytesRead = content(1); 171 172 %TODO see below 173 %FIXME fix outputting uint8, convert to double first! 174 171 175 % avoid index out of bounds 172 176 tmpEnd = min(BytesRead + 1, length(content)); -
branches/behrens/RWTHMindstormsNXT/SendMotorSettings.m
r79 r100 1 1 function SendMotorSettings(f_port, f_power, f_angle, f_speed, f_sync, f_ratio, f_ramp) 2 % Sends previously specified settings to currentactive motor.2 % Sends previously specified settings to the currently active motor. 3 3 % 4 4 % Syntax … … 19 19 % 20 20 % Note: 21 % All settings like power, angle limit and so on, will only take effect once you send them to the22 % motor using THIS function. Note that if you have synced two motors together ,this function21 % All settings like power, angle limit, and so on, will only take effect once you send them to the 22 % motor using THIS function. Note that if you have synced two motors together this function 23 23 % internally sends two packets to both the motors. This is required, but you can work as if this 24 24 % was just one command. -
branches/workshop/Accelerator/GetAccelerator.m
r34 r100 4 4 %-----------------------------LSWRITE---------------------------------- 5 5 6 % create this I2C command. basically all we want to do is request 17 % byte , the current sensor reading!6 % create this I2C command. basically all we want to do is request 6 7 % bytes, the current sensor reading! 8 8 9 9 RequestLen = 6; 10 I2Cdata = hex2dec(['02'; '42']); % Read Measurement Byte 0 (see LEGO Mindstorms NXT 11 % Ultrasonic Sensor - I2C Communication Protocol) 10 I2Cdata = hex2dec(['02'; '42']); 12 11 13 12 NXT_LSWrite(f_sensorport, RequestLen, I2Cdata, 'dontreply') … … 23 22 % should never get ready... 24 23 24 %instead of "wasting time" in the idle loop below, waiting for the 25 %sensor to get ready, we could also just wait some time here and 26 %collect the sensor bytes then... 27 %pause(0.015); 28 29 25 30 BytesReady = 0; 26 while (BytesReady == 0) 27 %TODO some sort of timeout in here in case we never get an answer? 31 ticID = 34; %fixme randomly, dangerous 32 timeout = 2; % in s 33 tictic(ticID); 34 status = -1; 35 %idlecount = 0; 36 while ((BytesReady < 6) || (status ~= 0)) && (toctoc(ticID) < timeout) 37 28 38 [BytesReady status] = NXT_LSGetStatus(f_sensorport); 39 if status == 221 % communication bus error 40 % recursive! 41 acc_vector = GetAccelerator(f_sensorport); 42 return 43 end%if 44 %idlecount = idlecount + 1; 29 45 end%if 30 46 31 acc_vector = -1; 47 %fprintf('idlecount = %d \n', idlecount) 48 % if (status ~= 0) || (BytesReady < 6) 49 % disp('whoa') 50 % end%if 51 52 acc_vector = [NaN NaN NaN]; 32 53 33 54 %% If ready get object distance (ultrasonic sensor value) … … 38 59 [data BytesRead] = NXT_LSRead(f_sensorport); 39 60 61 % IMPORTANT, DON'T FORGET!!! 62 % or change in NXT_LSRead 63 data = double(data); 64 40 65 if BytesRead > 5 41 if (data(1) > 127) data(1) = data(1) - 256; end 66 % as seen in the hitechnic example code... 67 % this is just a byte shift and could be done better, but 68 % should work 69 if (data(1) > 127) 70 data(1) = data(1) - 256; 71 end 42 72 if (data(2) > 127) data(2) = data(2) - 256; end 43 73 if (data(3) > 127) data(3) = data(3) - 256; end … … 48 78 49 79 %------------------------------------------------------------------ 80 else 81 [tmp msg] = checkStatusByte(status); 82 fprintf('Invalid sensor reading, %d bytes received, status %d: %s\n', BytesReady, status, msg); 83 50 84 end%if 51 85
