Dependencies:   ros_lib_kinetic

Revision:
25:88e6cccde856
Parent:
24:bc852aa89e7a
Child:
26:7c59002c9cd7
--- a/LLComms.cpp	Mon Dec 17 14:34:37 2018 +0000
+++ b/LLComms.cpp	Mon Dec 17 15:09:44 2018 +0000
@@ -76,9 +76,9 @@
     unsigned int intMsg = intValue;
     // Calculate checksum (the decimal sum of the position data)
     int intCheckSum = 0, intTempVar = intValue;
-    while( intTempVar>0 ) {
+    while( intTempVar>0 ) { //591
         intCheckSum += intTempVar%10;
-        intTempVar = (int)(intTempVar/10);
+        intTempVar = floor(intTempVar/10.0);
     }
     // Add checksum to message
     intMsg = intMsg<<5;
@@ -106,17 +106,15 @@
     // Get data from controller
     int intPosSPI_Rx[N_CHANNELS]; // 16bit position value received over SPI from the actuator 
     int intPresSPI_Rx[N_CHANNELS]; // 16bit pressure value received over SPI from the actuator 
+    *cs_LL[channel] = 0; // Select relevant chip
     if( channel < 4 ) {
-        *cs_LL[channel] = 0; // Select relevant chip
         intPosSPI_Rx[channel] = spi_0.write(intPositionMsg); // Transmit & receive
-        intPresSPI_Rx[channel] = intPosSPI_Rx[channel] | spi_0.write(intVelocityMsg); // Transmit & receive
-        *cs_LL[channel] = 1; // Deselect chip
+        intPresSPI_Rx[channel] = intPresSPI_Rx[channel] | spi_0.write(intVelocityMsg); // Transmit & receive
     } else {
-        *cs_LL[channel] = 0; // Select relevant chip
-        intPosSPI_Rx[channel] = spi_0.write(intPositionMsg); // Transmit & receive
-        intPresSPI_Rx[channel] = intPosSPI_Rx[channel] | spi_0.write(intVelocityMsg); // Transmit & receive
-        *cs_LL[channel] = 1; // Deselect chip
+        intPosSPI_Rx[channel] = spi_1.write(intPositionMsg); // Transmit & receive
+        intPresSPI_Rx[channel] = intPresSPI_Rx[channel] | spi_1.write(intVelocityMsg); // Transmit & receive
     }
+    *cs_LL[channel] = 1; // Deselect chip
     isDataReady[channel] = 0; // Data no longer ready, i.e. we now require new data
     
     /*if(channel == 0) {
@@ -163,76 +161,4 @@
 void LLComms::fall4(void) { common_fall_handler(4); }
 void LLComms::fall5(void) { common_fall_handler(5); }
 void LLComms::fall6(void) { common_fall_handler(6); }
-void LLComms::fall7(void) { common_fall_handler(7); }
-
-// NEEDS CALIBRATING
-/*double LLComms::ReadADCPosition_mtrs(int channel) {
-    unsigned int outputA;
-    unsigned int outputB;
-    int output;
-    double dblOutput;
-
-    if( channel < 4 ) {
-        spi_0.format(8,0);
-        spi_0.frequency(1000000);
-        
-        *cs_ADC[channel] = 0;
-        spi_0.write(PREAMBLE);
-        outputA = spi_0.write(CHAN_3);
-        outputB = spi_0.write(0xFF);
-        *cs_ADC[channel] = 1;
-    } else {
-        spi_1.format(8,0);
-        spi_1.frequency(1000000);
-        
-        *cs_ADC[channel] = 0;
-        spi_1.write(PREAMBLE);
-        outputA = spi_1.write(CHAN_3);
-        outputB = spi_1.write(0xFF);
-        *cs_ADC[channel] = 1;
-    }
-    
-    outputA = outputA & DATA_MASK;
-    outputA = outputA<<8;
-    output = (outputA | outputB);
-    output = 4095- output;
-    dblOutput = (double) (output);
-    dblOutput = dblOutput*0.0229 - 21.582;
-    return dblOutput;
-}
-    
-double LLComms::ReadADCPressure_bar(int channel) {
-    unsigned int outputA;
-    unsigned int outputB;
-    int output;
-    double dblOutput;
-
-    if( channel < 4 ) {
-        spi_0.format(8,0);
-        spi_0.frequency(1000000);
-        
-        *cs_ADC[channel] = 0;
-        spi_0.write(PREAMBLE);
-        outputA = spi_0.write(CHAN_1);
-        outputB = spi_0.write(0xFF);
-        *cs_ADC[channel] = 1;
-    } else {
-        spi_1.format(8,0);
-        spi_1.frequency(1000000);
-        
-        *cs_ADC[channel] = 0;
-        spi_1.write(PREAMBLE);
-        outputA = spi_1.write(CHAN_1);
-        outputB = spi_1.write(0xFF);
-        *cs_ADC[channel] = 1;
-    }
-    
-    outputA = outputA & DATA_MASK;
-    outputA = outputA<<8;
-    output = (outputA | outputB);
-    
-    dblOutput = (double)(output);
-    dblOutput = dblOutput-502.0;
-    dblOutput = dblOutput/4095.0*8.0;
-    return dblOutput;
-}*/
\ No newline at end of file
+void LLComms::fall7(void) { common_fall_handler(7); }
\ No newline at end of file