Save Servo Speed Settings

 
#1

Is there a way to save the Servo Speed settings. I can't seem to find any info on it. I loose the settings when I re-load a project.

Ron

#2

Can't you just use an init script in your project to set your servo speeds? You can also just use the script in the connection control. When the ezb connects all servo speeds will be set as required...
So in essence they are saved...

Code:


#init script
servo(D3,30)
servospeed(D3,2)
servo(D4,90)
servospeed(D4,1)
servo(D0,90)
servospeed(D0,1)

#3

Hi Richard,

Thanks for the suggestion. I do have need to make adjustments so I wanted to keep the sliders. I wanted to have the last settings saved. Similar issue to the camera grid lines.

Ron

#4

This tutorial should help you... Reading and writing to files
Look to use FileWrite and fileRead commands... see below from the script editor. You can save your settings in a plain text file when you run your init script it can read the saved settings (servo speeds or positions or whatever) from the previously saved text file... You will need to create a "shutdown" script in order to save your new settings to the text file...

Code:


FileDelete( filename )
Deletes a file on your computer
Example: FileDelete(“c:\temp\mylog.txt”)

FileWrite( filename, contents )
Appends text to the specified file. This does not append a new line.
Example: FileWrite(“c:\temp\mylog.txt”, “My Variable: “ + $x)
Example: FileWrite(“c:\temp\mylog.txt”, “Servo Position: GetServo(d2)”)

FileWriteLine( filename, contents )
Appends text as a new line to the specified file.
Example: FileWriteLine(“c:\temp\mylog.txt”, “My Variable: “ + $x)
Example: FileWriteLine(“c:\temp\mylog.txt”, “Servo Position: GetServo(d2)”)

FileReadClose( filename )
Closes the file from reading.
This must call must be performed before writing to the file. Once you begin reading from the file, the file is OPEN. Closing the file will reset to the start once you begin reading again.
Example: FileReadClose(“c:\temp\mylog.txt”)

FileReadReset( filename )
Resets the file to the beginning.
If you read to the end of a file, this function must be called to reset reading from the beginning of the file.
Example: FileReadReset(“c:\temp\mylog.txt”)

FileExists( filename )
Returns a 1 or 0 if the specified file exists.
Example: $fileExists = FileExists(“c:\temp\mylog.txt”)

FileReadEnd( filename )
Returns a 1 or 0 if the file has reached the end.
Example: $fileEnd = FileReadEnd(“c:\temp\mylog.txt”)

FileReadChar( filename )
Returns the next character in the specified file
Example: $char = FileReadChar(“c:\temp\mylog.txt”)

FileReadLine( filename )
Returns the next line of the specified filename.
Example: $line = FileReadLine(“c:\temp\mylog.txt”)

FileReadAll( filename )
Returns the entire contents of the specified file.
Example: $contents = FileReadAll(“c:\temp\mylog.txt”)

FileReadLineRandom( filename )
Returns a random line within the specified file
Example: $randomLine = FileReadLineRandom(“c:\temp\mylog.txt”)

#5

Richard is correct, you can save the last value to a text file to be reloaded. Otherwise, the value is hardcoded by script. See the Servo Speed control manual help here, which has additional information: http://www.ez-robot.com/Tutorials/Help.aspx?id=168

Specifically, why the value doesn't save. Because the servo position must be initialized before the servo speed. Also, servo positions are not maintained either by their respective controls. This must all be done with an initialization script in the connection control.

#6

Thanks Again,

By using this script I will not only be able to save last positions, and speeds of the servos but also variables, like counters and their stored data. This will help in more than what I posted.

Ron

#7

You bet!

This loads the saved data, as an example...

Code:


# Loads the data in the Connection Control

$filename = "c:\temp\settings.txt"

if (FileExists($filename))

# Make sure we are at the top of the file
FileReadReset($filename)

# each line of the file is a different setting in order

$Variable1 = FileReadLine($filename)
$Variable2 = FileReadLine($filename)
$Speed1 = FileReadLine($filename)
$servoPosition1 = FileReadLine($filename)
$speed2 = FileReadLine($filename)
$servoPosition2 = FileReadLine($filename)

# close the file from reading
FileReadClose($filename)

Servo(d0, $servoPosition1)
ServoSpeed(d0, $speed1)

Servo(d1, $servoPosition2)
ServoSpeed(d1, $speed2)

endif




And saving the data, such as...

Code:


# Saves the data

$filename = "c:\temp\settings.txt"

if (FileExists($filename))
FileDelete($filename)
endif

# each line of the file is a different setting in order

FileWriteLine($filename, $Variable1)
FileWriteLine($filename, $Variable2)
FileWriteLine($filename, GetServo(d0))
FileWriteLine($filename, GetServoSpeed(d0))
FileWriteLine($filename, GetServo(d1))
FileWriteLine($filename, GetServoSpeed(d1))



This saves and loads each setting as a different line. The order of the lines is important. You can always load the file into notepad after to see what it saved.