Simple Motor Controller - Analog brake controll?

Hello, is it somehow possible to change the brake settings with a analog input?
THX

Hello.

The brake settings can only be changed through the Simple Motor Control Center or through TTL serial commands while the Simple Motor controller is in Serial/USB mode input mode. You cannot change the brake settings through the analog interface. However, you could use a microcontroller to read your analog signals and send the corresponding serial commands to the Simple Motor Controller. You can read more about the Simplr Motor Controller’s input modes and serial commands in the Simple Motor Controller user’s guide.

- Grant

That was what i thought…
Thank you for clarify

To get a control for the brake amount i connected a arduino mini to the smc and used the advanced arduino example to control the smc with a serial protocol. all works great but with the the brake_amount i have the trouble that i can set it, but its reseting directly to the preset of the smc. i can’t find help in the doc or the forum…
Thats my code… if i look at the serial monitor i can see that just after setting the brake amount its okay but than it flips back to the preset…

[code]#include <SoftwareSerial.h>
#define rxPin 10 // pin 3 connects to SMC TX
#define txPin 11 // pin 4 connects to SMC RX
#define resetPin 12 // pin 5 connects to SMC nRST
#define errPin 13 // pin 6 connects to SMC ERR
#define analogPin A3 // pin 6 connects to SMC ERR
int sensorValue = 0; // value read from the pot
int outputValue = 0; // value output to the PWM (analog out)
int stopVal; // value output to the PWM (analog out)
int geschw; // value output to the PWM (analog out)
int brakeVal = 0;

SoftwareSerial smcSerial = SoftwareSerial(rxPin, txPin);

// some variable IDs
#define ERROR_STATUS 0
#define LIMIT_STATUS 3
#define TARGET_SPEED 20
#define INPUT_VOLTAGE 23
#define TEMPERATURE 24

// some motor limit IDs
#define FORWARD_ACCELERATION 9
#define REVERSE_ACCELERATION 9
#define DECELERATION 9
#define BRAKE_AMOUNT 22

// read a serial byte (returns -1 if nothing received after the timeout expires)
int readByte()
{
char c;
if(smcSerial.readBytes(&c, 1) == 0){ return -1; }
return (byte)c;
}

// required to allow motors to move
// must be called when controller restarts and after any error
void exitSafeStart()
{
smcSerial.write(0x83);
}

// speed should be a number from -3200 to 3200
void setMotorSpeed(int speed)
{
if (speed < 0)
{
smcSerial.write(0x86); // motor reverse command
speed = -speed; // make speed positive
}
else
{
smcSerial.write(0x85); // motor forward command
}
smcSerial.write(speed & 0x1F);
smcSerial.write(speed >> 5);
}

// BrakeAmount should be a number from 0 to 32
void setMotorBrake(int brake)
{
smcSerial.write(0x92); // motor brake command
smcSerial.write(brake);
// here i check the brake settings - seems to be okay
Serial.print("SetBrake = ");
Serial.println(getVariable(BRAKE_AMOUNT));
}

unsigned char setMotorLimit(unsigned char limitID, unsigned int limitValue)
{
smcSerial.write(0xA2);
smcSerial.write(limitID);
smcSerial.write(limitValue & 0x7F);
smcSerial.write(limitValue >> 7);
return readByte();
}

// returns the specified variable as an unsigned integer.
// if the requested variable is signed, the value returned by this function
// should be typecast as an int.
unsigned int getVariable(unsigned char variableID)
{
smcSerial.write(0xA1);
smcSerial.write(variableID);
return readByte() + 256 * readByte();
}

void setup()
{
Serial.begin(115200); // for debugging (optional)
smcSerial.begin(19200);

// briefly reset SMC when Arduino starts up (optional)
pinMode(resetPin, OUTPUT);
digitalWrite(resetPin, LOW); // reset SMC
delay(1); // wait 1 ms
pinMode(resetPin, INPUT); // let SMC run again

// must wait at least 1 ms after reset before transmitting
delay(5);

// this lets us read the state of the SMC ERR pin (optional)
pinMode(errPin, INPUT);

smcSerial.write(0xAA); // send baud-indicator byte
setMotorLimit(FORWARD_ACCELERATION, 9);
setMotorLimit(REVERSE_ACCELERATION, 9);
setMotorLimit(DECELERATION, 9);

// clear the safe-start violation and let the motor run
exitSafeStart();
}

void loop()
{
Serial.println("*****************");
sensorValue = analogRead(analogPin);
// map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1001, -3200, 3200);
stopVal = constrain(outputValue, -50, 50);
brakeVal = map(stopVal, -50, 50, 0, 32);
if(stopVal==outputValue){geschw=0;}else{geschw=outputValue;}
if(geschw==0){setMotorBrake(brakeVal);}
// change the analog out value:
// analogWrite(analogOutPin, outputValue);

// print the results to the serial monitor:
Serial.print(“sensor = " );
Serial.print(sensorValue);
Serial.print(”\t output = “);
Serial.println(outputValue);
Serial.print(”\t stop = ");
Serial.println(stopVal);
// setMotorSpeed(3200); // full-speed forward
// signed variables must be cast to ints:
// Serial.println((int)getVariable(TARGET_SPEED));
// delay(1000);
// setMotorSpeed(-3200); // full-speed reverse
Serial.print("Speed = ");
Serial.println((int)getVariable(TARGET_SPEED));
setMotorSpeed(geschw);
delay(1000);

// write input voltage (in millivolts) to the serial monitor
Serial.print(“VIN = “);
Serial.print(getVariable(INPUT_VOLTAGE));
Serial.println(” mV”);
// at this point i check the brake settings again
Serial.print("Brake = “);
Serial.print(getVariable(BRAKE_AMOUNT));
Serial.print(”\t brakeVal = ");
Serial.println(brakeVal);

// if an error is stopping the motor, write the error status variable
// and try to re-enable the motor
if (digitalRead(errPin) == HIGH)
{
Serial.print(“Error Status: 0x”);
Serial.println(getVariable(ERROR_STATUS), HEX);
// once all other errors have been fixed,
// this lets the motors run again
exitSafeStart();
}
}[/code]

does someone has an idea??

THX

If you are getting an error, it might be resetting your braking values. Could you post your settings file? Could you also post a screenshot of the actual output you are seeing on the serial monitor and a screenshot of the Simple Motor Control Center status tab?

- Grant

Finaly i found the problem…
After the brake-amount setting there was still a speed setting (speed =0) but this command resets the brake-amount to the preset.
Now it works fine!
THX

BTW: Does the SMC recharge the battery when the brake-amount is higher then 0 and i pusch it or it goes downhill? Or is the energy burned in some diodes?

Thanks for sharing what the problem was. I am glad you got it working.

The SMC does not have regenerative braking; the energy will just be dissipated.

- Grant