EcoModder.com

EcoModder.com (https://ecomodder.com/forum/)
-   Open ReVolt: open source DC motor controller (https://ecomodder.com/forum/open-revolt-open-source-dc-motor-controller.html)
-   -   CougArd Explorer (https://ecomodder.com/forum/showthread.php/cougard-explorer-13463.html)

Greg Fordyce 06-03-2010 07:09 PM

CougArd Explorer
 
2 Attachment(s)
I have assymbled one of the Cougar controllers and need a way to protect my lithium battery pack if the SOC is getting low. The controller can limit battery amps if you send a command over the serial port, for example "bat-amps-lim 200" will prevent the controller from drawing more than 200 amps. So the idea is this, when my bms sends a low battery signal I tell the controller to lower battery amps. Just keep doing this, reducing battery amps more and more until you get to 1 amp ( setting the value to zero disables the battery amp limit). This will allow you time to get the car off the road without suddenly cutting all power.

So how to send this command to the controller? I have set myself a few rules, first and most important is the controller will not be modified from the kit/design that is available. This will help prevent forking of the controller project. I will make up the rest of the rules as I come up with them! :D My controller is sealed now so I can't go in and start changing things.

I am using a Arduino Mega to comunicate over the serial port with the Cougar controller. VERY IMPORTANT, DON'T CONNECT A ARDUINO DIRECTLY TO THE SERIAL PORT ON THE CONTROLLER. The voltages on the controller serial port are +/-10 volts and will likely fry something. You need to use a serial to ttl adapter that converts the serial voltages to the 5v ttl voltage on the arduino. I am using a Sparkfun RS232 Shifter SMD
It took me a while to figure out how to connect it. You need a "null modem" or crossover cable, basically it switches pin 2 and 3 on the rs232 ports. Then to connect to the arduino you connect RX on the Shifter to TX on the Arduino and TX to RX, plus a 5v and ground wire. The reason I am using the Mega is it has 4 hardware UARTS for serial comunication. I have a Tellymate Shield connected to the main serial port, the cougar connected to the second and my BMS will be connected to the third, sending battery amp and amp hour data.

So far I can send commands to the controller, save and display the data stream on a lcd monitor. By connecting the low voltage warning from the BMS, to the Arduino, it will then send the appropiate commands to the controller. I will probably start with a simple look up table such as;

warning 1 - 200 amps
warning 2 - 150 amps
warning 3 - 100 amps
warning 4 - 50 amps
warning 5 - 20 amps
warning 6 - 1 amp
:turtle:

I will post the sketch after I have done some more work on it.

Greg

MPaulHolmes 06-03-2010 11:59 PM

That is very clever, and just plain beautiful. You are what they call an "Engineer". They grow them real smart over there in Scotland!

By the way, if I had my own controller, yours would look way more fancy and professional. Nice job!

mrbigh 11-20-2010 04:02 PM

CougArd Explorer
 
Greg, what is the outcome of your Arduino interface?

Greg Fordyce 11-21-2010 06:22 AM

Quote:

Originally Posted by mrbigh (Post 205222)
Greg, what is the outcome of your Arduino interface?

Sadly at the moment it is on hold. The first priority is getting my EV on the road, after all the CougArd Explorer isn't much use without an EV to put it in. :rolleyes: I have all the bits, but other things keep getting in the way, work, major house renovations and life in general. I am thinking about buying a can of time, but even it's on back order! :eek:

Seriously though, I am moving away from the Arduino platform for this, at least for the moment. The original reason for choosing the Arduino was because my BMS couldn't support serial comms faster than 9600 baud and the Cougar is at 19200. So the idea was for the CougArd Explorer to sit in between the Controller and my BMS and maybe eventually move the BMS master functions to the CougArd Explorer.

But things have changed on the BMS front and the project can now support 19200 baud serial comms. This is because we have moved from the original Picaxe chips to using bare Microchip pics and the Pic Basic Pro development environment. So now I have the possibility of directly connecting the bms to the controller. The first task will be to get the current limit working as I described above when the battery pack starts getting low. Then I want to monitor data from the controller starting with battery amps and amp hour data. The BMS has a built in current measurement, but I want to use the bms current data for battery charging and dc-dc loads from my pack. This will allow a smaller and more accurate sensor for this and use the controllers motor amp sensor for the motor load.

With the Arduino I was able to send commands to the controller and also read the serial data. Parsing the data string and storing the values to variables was proving a bit harder, but this looks to be quite simple with PicBasic, although I haven't actually tried it yet. :eek: Another advantage of PicBasic over the Arduino is connection is possible with a couple of resistors, no RS232 level shifter required.

My plan is to get the car on the road soon and get back to working on this project early in the new year.

Greg

Greg Fordyce 12-05-2010 11:12 AM

CougArd Explorer rides again!
 
Now that my car is nearly on the road, after more than a year of working on it,:( I am looking again at my CougArd Explorer idea. The basic idea is to give some of the functionality of the rtd explorer program in a small embedded platform. Originally I was going to use a Arduino for this, hence the name. The Arduino has been ditched, but I like the name so am going to keep it. That, and I am too lazy to think of a new name! :p

So while I am waiting for my µLCD-32PT(GFX) - 4DGL Display Modules to arrive, I have written some code for it. At this point I want to prove that I can send commands to the controller, receive the data stream and store the values into variables that can be manipulated/displayed. This code should display as text the data from the controller. It compiles o.k., but probably has lots of bugs in it. So here it is, but please note, I am a rubbish programmer. I am however open to lots of suggestions on improving the code.:D

Code:

#platform "uLCD-32PT_GFX2"

/*----  CougArd Explorer by Greg Fordyce. Version 0.01alpha 05/12/2010 -------
------    4DGL Workshop 3 Version 3.1.0.4 - Platform uLCD32PT_GFX2    -------
------------------------compiled size 791 bytes of 15360----------------------

**************************** General Information ******************************

This software carries no warranty or guarantee of any kind! Use at
your own risk, and I make no claims as to its suitability for a particular
function. Prospective users must evaluate the system before using it, and no
liability will be entertained by myself in any shape or form whatsoever.
The software has been produced at low cost for the benefit of
the EV & electronic community. The software is available free via the internet.
Users may modify or adapt the system as they see fit. If you are not fully
competent to work on potentially lethal battery systems and high voltages,
then do not experiment with or use this system. Be aware that vehicle
modifications can lead to invalidated insurance and warranty issues. You the
end user remain fully liable for any modifications made to your vehicle.

/****************************** Description ************************************

This software is to capture the real time data stream from the cougar controller
and display it in a graphical interface to the driver. This first version is a
proof of concept and just displays the info as test after capturing and storing the
data to variables. It compiles o.k. but has not yet been tested on the actual
display. It probably has lots of bugs in it at the moment. More info, see links.
http://ecomodder.com/forum/showthread.php/cougard-explorer-13463.html
http://ecomodder.com/wiki/index.php/ReVolt

/************************* Connection warning ***********************************

The cougar controller uses a serial RS232 port if built to the standard design.
The uLSD-32PT_GFX2 uses 3.3v ttl level serial comms (5 volt tolerent). You must use
a serial to ttl level shifter/converter. Direct connection of the display to the
serial port will likely damage the display.
*********************************************************************************/
///////////  Constants  ////////////////////////////////////////////////////////////


///////////  Data  /////////////////////////////////////////////////////////////////

#DATA byte rtd_pointer 3,10,17,24,31,39,47,53      // Address locations in cougar data string for values

#END


///////////  Variables  ////////////////////////////////////////////////////////////

var i, p, n;
var cougTXbuf[10];  // This will allow us to build strings of up to 20 characters to send commands to the controller
var cougRXbuf[33];  // Data string format from controller
                    //"TR=xxx CR=xxx CF=xxx PW=xxx HS=xxxx RT=xxxx FB=xx BA=xxx AH=xxx.x\r\n"
var coug_rtd[9];    // Data from controller
                    // [0] TR 'throttle'
                    // [1] CR 'current reference'
                    // [2] CF 'current feedback'
                    // [3] PW 'PWM'
                    // [4] HS 'heatsink'
                    // [5] RT 'raw throttle'
                    // [6] FB 'fault bits'
                    // [7] BA 'battery amps'
                    // [8] AH 'amp hours' note: the 1/10 value is ignored

func rtd_capture()                              // This function parses the rtd string and assigns
                                                // word values of all integer numbers found  in the string

    n:=str_Find(&p,"TR");                      // Check for valid string from controller
    if (n > 0 && n < 3)                        // "TR" should be found at front of string
        i:=0;
        while(str_GetW(&p, &coug_rtd[i++]) != 0);    // parse cougarRXbuf and store values to coug_rtd
        com_Init(cougRXbuf,33,0);              // reset RX buffer
    else
        n:=0;                                  // if we get here there is a problem with the string
    endif
endfunc

func main()
    com_SetBaud("COM0","1920");                        // Cougar comms is 19200 8-n-1
    gfx_Cls();
    gfx_Set(SCREEN_MODE,LANDSCAPE);
    txt_Set(FONT_SIZE, FONT2);
    com_Init(cougRXbuf,33,0);                          // set up a interrupt driven ring buffer for comms
    com_TXbuffer(cougTXbuf, 10);                        // set up the TX buffer
    //com_TXbufferHold(ON);                            // probably not required here
    to(cougTXbuf); print("rtd-period 500\r\n");        // Cougar sends rtd string every 500ms
    //com_TXbufferHold(OFF)                            // probably not required here
    pause(10);                                          // wait for response from controller
    while(com_Count()) putch(serin());                  // print echo response from controller to screen

    p:= str_Ptr(cougRXbuf);
    repeat
    while(!com_Full()) continue;                        // wait till com buffer fills
    rtd_capture();                                      // Check rtd data
            if (n != 0)                                // print rtd variables
                i := 0 ;
                print("Throttle is  ", coug_rtd[i++], "\n");
                print("Current Ref  ", coug_rtd[i++], "\n");
                print("Current Fdbk  ", coug_rtd[i++], "\n");
                print("PWM          ", coug_rtd[i++], "\n");
                print("Raw Heatsink  ", coug_rtd[i++], "\n");
                print("Raw Throttle  ", coug_rtd[i++], "\n");
                print("Fault bits    ", coug_rtd[i++], "\n");
                print("Battery Amps  ", coug_rtd[i++], "\n");
                print("Amp Hours    ", coug_rtd[i], "\n");
            else
                print("ERROR: ", [STR] cougRXbuf, "\n"); // print buffer as diagnostic output
                com_Init(cougRXbuf,33,0);                // reset RX buffer
            endif
    // endif

    forever
endfunc


Greg Fordyce 12-05-2010 05:49 PM

Cougard Explorer on Launchpad
 
I have added this project to the Ubuntu Launchpad site. It is a code hosting site like Sourceforge that manages revisions in software. One of the neat things is anyone can create a branch of the project, and their changes can be merged with the existing project. Be warned that if you have never used it before the learning curve is very steep, don't ask me any questions about it as I am still trying to figure it out myself. :confused:

Anyway here is the link. https://launchpad.net/cougard and you don't need to register to view or download files, only if you want to contribute through the launchpad site.

sawickm 12-06-2010 08:20 AM

Quote:

Originally Posted by Greg Fordyce (Post 208033)
I have added this project to the Ubuntu Launchpad site. It is a code hosting site like Sourceforge that manages revisions in software. you don't need to register to view or download files, only if you want to contribute through the launchpad site.

Greg,

I added your link to the Open ReVolt Wiki under "Software"; Open ReVolt - EcoModder

Mark :D

Greg Fordyce 12-29-2010 12:28 PM

Small steps and virtual controllers
 
1 Attachment(s)
I have had some time to sit down with the 4d display and have got it to read the data stream from the controller. :) Well not exactly the controller, but a virtual controller using the arduino that I was originally going to use for this project. ;) I have attached the arduino sketch, it's just a very simple loop that spits out a data stream.

So the display can read the ascii data stream, just have to get it to store the data in some variables, but this bit has me stumped at the moment. So I have posted a question on the manufactures forum. Can't extract numerical values from ascii string. - 4D SYSTEMS FORUM

Greg

Greg Fordyce 01-02-2011 06:15 PM

I've got a simple version that is capturing the data stream. Newest files uploaded here. ~greg.fordyce/cougard/trunk : files for revision 2

jackbauer 01-09-2011 07:13 AM

Just purchased the display from 4d systems so will hopefully be able to help out with this project. Have you any pics of the display and information on connecting the hardare?

Greg Fordyce 01-09-2011 09:56 AM

2 Attachment(s)
Quote:

Originally Posted by jackbauer (Post 213987)
Just purchased the display from 4d systems so will hopefully be able to help out with this project. Have you any pics of the display and information on connecting the hardare?

I have attached some pics of where I am at the moment, quality not great, sorry about that. The first one shows a screen shot of the 4d display. Top 2 rows is the raw ascii string from the, well in this case my Arduino. Then you have the actual values converted from the ascii string, stored in variables and displayed on screen with some other diagnostic info to help in program debuging.

The second picture shows the display, arduino and laptop with the Arduino serial monitor running. This allows me to see what the arduino is sending, again useful for debuging. So far I have not actually connected the 4d display to the actual cougar controller, been working in the warmth of my house instead of in the garage with the car, where the controller is, but the arduino provides a useful data stream to test the software against.

Actual connection to the controller will be up to individual requirements. In my case I also plan on using the displays 2nd serial uart to connect to my bms. The bms will also supply 5v and earth for the display. Just have to make sure the earths are common between the controller and bms. I will use the spark fun rs232 level shifter I mentioned in the first post of this thread to connect the controllers serial port to the display. The same warnings I posted about not connecting the serial port directly to the arduino also apply here. The 4d displays are 3.3 volt ttl serial, but are 5 volt tolerant. On the 4d site they recommend using a resistor on the 4d rx pin when connecting it to a 5v ttl signal, I am using a 330 ohm for this.

Another option would be to power the display from the control board. It should be a fairly simple matter to bring out a 4 conductor cable with 5 volt, earth, rx and tx at ttl levels for connection to the display. It is up to individual users to check and double check their connections as I imagine it wouldn't be difficult to let out the magic smoke on one of these displays if you get the connections wrong.

jackbauer 01-09-2011 10:06 AM

Thanks. Soon as the display turns up i'll have a go. BTW how do you program the display? via serial?

Greg Fordyce 01-09-2011 10:25 AM

Quote:

Originally Posted by jackbauer (Post 213996)
Thanks. Soon as the display turns up i'll have a go. BTW how do you program the display? via serial?

I use one of these. I think people have made there own as well, have a look on the 4d forums for info.

jackbauer 01-17-2011 03:51 PM

3 Attachment(s)
My 4D systems display turned up today. word of advice. Buy the usb programmer! Had an epic struggle to get the device working on rs232. The culprit is the reset line. For programming it must be pulled low briefly. I eventually found a little obscure circuit on the 4d forums and modified it slightly to avoid using the max232 for the the reset signal. A 1N4001 diode works fine as shown. Now i can get on with programming the thing:D

jackbauer 01-18-2011 10:59 AM

1 Attachment(s)
Got a chance today to do a few mods to the code. Its now running on the bench from a cougar control board. Quick video and new code attached.
http://www.youtube.com/watch?v=9mSvmUTencU

jackbauer 01-20-2011 03:56 PM

1 Attachment(s)
Made some progress with the display. Cleaned up the refresh to get rid of unwanted data , heatsink temp now in degrees c and rpm measurement implemented. Simple touch screen interface also implemented.
http://www.youtube.com/watch?v=6g8O8hLwPbc

Greg Fordyce 03-06-2011 03:21 AM

As always, I have to many things to do. Lately I have been working on getting the car on the road. Hope to get back to this reasonably soon. As for schematics, there aren't any. You need to use a RS232 to serial TTL level converter. Spark fun has one, see previous posts.

EDIT: I tell a lie about the schematics, Jack has posted one using a MAX232 chip, see previous posts.

Greg Fordyce 06-04-2011 11:54 AM

2 Attachment(s)
So many things to do, but now that my car is on the road I needed to get my display operational. So I have mounted it in a small lcd screen enclosure I had lying around and got rid of the diagnostic output on the display. For normal daily use I am just displaying Motor Amps, Battery Amps, Temperature and Amp hours (just the integer value for now). Here's a pic.
Attachment 8621

The display in the middle of the dash (left side of picture) is my BMS display. Here's a close-up.
Attachment 8622

Ultimately my goal is to combine both displays into one. In theory either my BMS could communicate directly with the Cougar controller, but the serial to video chip is only capable of 16 characters by 9 lines, and as you can see by the distortion on the bottom it doesn't play nicely with the cheap chinese lcd display. Or I could get the 4D display to talk to my bms and bring all the data from the BMS and controller onto one screen. Either way it needs a lot of software coding to achieve.

I was hoping to post the software in this post, but I broke something while tidying it up.:mad: However, once I fix it, I will post it. :thumbup:

Greg

Greg Fordyce 06-04-2011 05:57 PM

As promised, the latest version of my code.

Code:

#platform "uLCD-32PT_GFX2"

/*----------  CougArd Explorer by Greg Fordyce.  04 June 2011 --------------
------    4DGL Workshop 3 Version 3.1.0.14 - Platform uLCD32PT_GFX2    -------
------------------------compiled size 817 bytes of 15360----------------------

**************************** General Information ******************************

This software carries no warranty or guarantee of any kind! Use at
your own risk, and I make no claims as to its suitability for a particular
function. Prospective users must evaluate the system before using it, and no
liability will be entertained by myself in any shape or form whatsoever.
The software has been produced at low cost for the benefit of
the EV & electronic community. The software is available free via the internet.
Users may modify or adapt the system as they see fit. If you are not fully
competent to work on potentially lethal battery systems and high voltages,
then do not experiment with or use this system. Be aware that vehicle
modifications can lead to invalidated insurance and warranty issues. You the
end user remain fully liable for any modifications made to your vehicle.

****************************** Description ************************************

This software is to capture the real time data stream from the cougar controller
and display it in a graphical interface to the driver. This first version is a
proof of concept and just displays the info as test after capturing and storing the
data to variables. It compiles o.k. but has not yet been tested on the actual
display. It probably has lots of bugs in it at the moment. More info, see links.
http://ecomodder.com/forum/showthread.php/cougard-explorer-13463.html
http://ecomodder.com/wiki/index.php/ReVolt

************************** Connection warning ***********************************

The cougar controller uses a serial RS232 port if built to the standard design.
The uLCD-32PT_GFX2 uses 3.3v ttl level serial comms (5 volt tolerent). You must use
a serial to ttl level shifter/converter. Direct connection of the display to the
serial port will likely damage the display. See cougard-explorer link above for
connection info and schematics.
*********************************************************************************/

var i, j, p, n;
var HStemp;        // In Celsius

var cougRXbuf[33];  // Data string format from controller
                    //"TR=xxx CR=xxx CF=xxx PW=xxx HS=xxxx RT=xxxx FB=xx BA=xxx AH=xxx.x\r\n"

var coug_rtd[9];    // Data from controller
                    // [0] TR 'throttle'
                    // [1] CR 'current reference'
                    // [2] CF 'current feedback'
                    // [3] PW 'PWM'
                    // [4] HS 'heatsink'
                    // [5] RT 'raw throttle'
                    // [6] FB 'fault bits'
                    // [7] BA 'battery amps'
                    // [8] AH 'amp hours' note: the 1/10 value is ignored

/* Heatsink look-up table (LUT). Raw heatsink values(RawHS)correspond to actual temp values (Cval). You may
  substitute your own values making sure you use appropiate corresponding values. You must have a
  RawHS value of 0 at the start and 1024 at the end. You may add any number of values that you like
  to the table. Formula to calculate look-up table for a 'stock' 2C controller can be found here;
  http://ecomodder.com/forum/showthread.php/paul-sabrinas-cheap-diy-144v-motor-controller-6404-411.html#post207171
*/

#DATA
    word RawHS  0, 250, 500, 630, 670, 1024
    word Cval -40,  20,  45,  65,  75,  270
#END



func main()
    gfx_Cls();
    gfx_Set(SCREEN_MODE,LANDSCAPE);
    txt_Width(2);
    txt_Height(2);
    print("Motor Amps    \n");
    print("Battery Amps  \n");
    print("Heatsink Temp \n");
    print("Amp Hours    \n");
    com_SetBaud(COM0,1920);              // Cougar comms is 19200 8-n-1
    repeat
    com_Init(cougRXbuf,64,0);            // set up a interrupt driven ring buffer for comms
    p:= str_Ptr(cougRXbuf);              // pointer
    while(!com_Full()) continue;        // wait till com buffer fills

//      str_Printf (&amp;p,"%s\n\n");    //uncomment to print buffer as diagnostic output

/***************Capture cougar data stream variables to array coug_rtd[]************************/
        i:=0;
        p := p + 3;
        str_GetW(&p, &coug_rtd[i]);      // coug_rtd[0] TR 'throttle'
        p := p + 4;
        i++ ;
        str_GetW(&p, &coug_rtd[i]);      // coug_rtd[1] CR 'current reference'
        p := p + 4;
        i++;
        str_GetW(&p, &coug_rtd[i]) ;    // coug_rtd[2] CF 'current feedback'
        p := p + 4;
        i++;
        str_GetW(&p, &coug_rtd[i]);      // coug_rtd[3] PW 'PWM'
        p := p + 4;
        i++;
        str_GetW(&p, &coug_rtd[i]) ;    // coug_rtd[4] HS 'heatsink'
        p := p + 4;
        i++;
        str_GetW(&p, &coug_rtd[i]) ;    // coug_rtd[5] RT 'raw throttle'
        p := p + 4;
        i++;
        str_GetW(&p, &coug_rtd[i]) ;    // coug_rtd[6] FB 'fault bits'
        p := p + 4;
        i++;
        str_GetW(&p, &coug_rtd[i]) ;    // coug_rtd[7] BA 'battery amps'
        p := p + 4;
        i++;
        str_GetW(&p, &coug_rtd[i]) ;    // coug_rtd[8] AH 'amp hours' note: the 1/10 value is ignored
        p := p + 5;
        com_Init(cougRXbuf,64,0);        // reset RX buffer

/************** Calculate heatsink tempurature from LUT **********************************************
http://ecomodder.com/forum/showthread.php/paul-sabrinas-cheap-diy-144v-motor-controller-6404-412.html#post207267
Thanks to user DJBecker for the look up table example using 16 bit maths to calculate tempurature in Celsius. */

      for (j:=1; coug_rtd[4] >= RawHS[j]; j++); // j is now pointing to the required value in the LUT
      HStemp := coug_rtd[4] - RawHS[j-1];
      HStemp *= Cval[j];
      HStemp += (RawHS[j-1] - coug_rtd[4])*Cval[j-1];
      HStemp /= RawHS[j] - RawHS[j-1];
      HStemp += Cval[j-1];

/************************************* Display controller data***************************************/

        txt_MoveCursor(0,14);
        print("    ");
        txt_MoveCursor(0,14);
        print(coug_rtd[2]);            // Motor Amps

        txt_MoveCursor(1,14);
        print("    ");
        txt_MoveCursor(1,14);
        print(coug_rtd[7]);            // Battery Amps

        txt_MoveCursor(2,14);
        print("    ");
        txt_MoveCursor(2,14);
        print(HStemp);                  // Heatsink tempurature in Celcius

        txt_MoveCursor(3,14);
        print("    ");
        txt_MoveCursor(3,14);
        print(coug_rtd[8]);            // Amp hours, interger value only.

forever
endfunc

Although it only displays 4 values, Motor amps, Battery amps, Heatsink temp and Ah, all values from the cougar real time data stream are captured and stored as variables, with one exception. The Amp hour data is only captured as an integer value. A bit more work is required to get the tenth of an amp figure. But what we do have is a useful drivers display of what I consider to be the most important info while driving.

The controller will need to be set to output the data stream using RTD explorer or moserial. I have set 'rtd_period 1000' and remember to send the 'save' command. I have not tested to see how fast a rtd stream it can handle, updating once a second is fine for driving, not to distracting.

Things that need to be done;

Fancy graphics instead of text display. After all that is why I bought the thing.:eek:

Fault bits display.

Data logging to built in uSD card slot. Ideally make the output a csv that is identical to the RTD explorer output.

Get the amp hour data to 0.1 of an ah.

Reduce battery amp limit when a low battery warning is received. Ideally use one of the available digital i/o pins that you can connect to whatever battery warning system you have.

This is some of my immediate goals for this project. Longer term goal is to use the second available serial port to get my bms data into the unit and have one display for both.

As you may have guessed, my projects don't move at any great pace,:turtle: but I am always open for code submissions if anyone else is wanting to play with one of these 4d displays. :)


All times are GMT -4. The time now is 08:32 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Content Relevant URLs by vBSEO 3.5.2
All content copyright EcoModder.com