View Single Post
  #12   Spotlight this post!  
Unread 13-06-2015, 09:07
teslalab2's Avatar
teslalab2 teslalab2 is offline
RogueBotix LLC
VRC #8091
Team Role: Mentor
 
Join Date: Feb 2015
Rookie Year: 2014
Location: Austin MN
Posts: 109
teslalab2 will become famous soon enoughteslalab2 will become famous soon enough
Re: Building a RogueBot!

Quote:
Originally Posted by timytamy View Post
You're running the Jags on CAN?

Would you mind sharing that code, I'd be very interested...

Of course! It's all going to be released with arduRIO. the arduino is not actually generating the can, its generating TTL, then I built a simple little circuit board to convert TTL to Uart, Then the first jaguar which must be a black jaguar is used as a Uart to can bridge. right now the canjag library I wrote is a mess and only fully supports voltage mode, I'm working on Vcomp mode right now, but I have some kinks to work out with scaling the values correctly. all in good time, hard to find time to write code when you work 10 hour days!

here is a little preview, I reverse engineered BDC-COMM to figure out how this works.

Code:
#include <CanJaguar.h>
#include "Arduino.h"
#include <SoftwareSerial.h>
SoftwareSerial canserial(2,3);
CanJaguar::CanJaguar(int rx,int tx){
}
//SoftwareSerial canserial(10,11);//rx,tx
void CanJaguar::Initialize(void){
vmode = false;
vcmode = false;
cmode = false;
smode = false;
pmode = false;
canserial.begin(115200);
}

void vcompenable(int id){ 
    byte message[] = {0xFF,0x04,id,0x08,0x02,0x02};
 canserial.write(message,sizeof(message));
}
void venable(int id){ 
    byte message[] = {0xFF,0x04,id,0x00,0x02,0x02};
 canserial.write(message,sizeof(message));
}

void encodebytes(float val,int data[]){
   int integer = (int)val;
   float decimal = val - integer;
   int numofdata = 0;
    if(decimal == 0xFF){
         data[numofdata++] = 0xFE;
         data[numofdata++] = 0xFE;
        }
            else if(decimal == 0xFE){
         data[numofdata++] = 0xFE;
         data[numofdata++] = 0xFD;
            }
                else{
                data[numofdata++] = decimal;
                }
        
        if(integer == 0xFF){
         data[numofdata++] = 0xFE;
         data[numofdata++] = 0xFE;
        }
            else if(integer == 0xFE){
         data[numofdata++] = 0xFE;
         data[numofdata++] = 0xFD;
            }
                else{
                data[numofdata++] = integer;
                }
    }
    
void CanJaguar::SetVoltage(int id,float value){
    if(!vmode){venable(id);vcmode=false;vmode=true;cmode=false;smode=false;pmode=false;}
    int stuff =  value*127.5;
    power = (stuff & 0xFFFF) | stuff << 8;          
    int data[3] = {0};  
    encodebytes(power,data);
    byte message[] = {0xFF,0x06,0x80+id,0x00,0x02,0x02,data[0],data[1],data[2],data[3]};  
 canserial.write(message,sizeof(message));
}

void CanJaguar::SetVcomp(int id,float value){
    if(!vcmode){vcompenable(id);vcmode=true;vmode=false;cmode=false;smode=false;pmode=false;}
    int stuff =  value;
    power = (stuff & 0xFFFF) | stuff << 16; //the first value converts the int, the second converts the float, serperate to 2 differnt values
        if(value < 0){ //also should be stuff&0xff
        power = 0xFFFF - power;
        }
    int data[3] = {0};  
    encodebytes(power,data);  
    byte message[] = {0xFF,0x06,0x80+id,0x08,0x02,0x02,0xfe,0xfe,0xfe,0xfe};// neg values subtraced from max end

 canserial.write(message,sizeof(message));
}
__________________
I need a jaguar development board for reprogramming a jaguars bootloader. if you have one that you want to sell, pm me. thanks

Run you CanJaguars on arduino with ArduRIO, you can also easily control Talons, Victors,Jaguars and Sparks on PWM. https://sourceforge.net/projects/ardurio/

Last edited by teslalab2 : 13-06-2015 at 09:18.
Reply With Quote