I there. Hope you all are well.
I am making a PTZ camera using UV-ZN2126 camera sensor. It is controlled through Pelco D.
I am using TMC5041 controller to control my stepper motors.
I have controlled all four motions i.e, UP, DOWN, LEFT and RIGHT Through pelco D.
The zoom function is in-built in camera and could be done through ONVIF software easily.
The problem I am facing is, I need to do speed variations of my Pan and tilt motion with camera zoom. It means that when 1x zoom, pan and tilt movement are fast. but when zoomed In like 26x, the speed could be controlled.
The zoom value is shown on camera OSD but i am unable to read it. If i could, i can easily complete my task.
I will be very thankful, if anyone could help.
This is what I receive from camera through RS485. Here zoom In command is shown followed by stop command.
The problem is Pelco D does not give zoom information i.e, how much zoomed the camera is. If it does, the speed of pan and tilt could easily be controlled.
But Is there any other way that I am missing?
If You provide links to the user manuals and datasheets maybe someone has a suggestion.
Kindly find the links to user manuals.
Camera module link:
http://www.hzhyws.com/en//uploads/Download/20210601/143817668ff6518.pdf
Stepper motor driver link:
https://www.trinamic.com/fileadmin/assets/Products/ICs_Documents/TMC5041_datasheet.pdf
Fine. I'm not able to deep diving for the moment but have patience. There are more helpers...
You could consider using an RS485 to Arduino interface board. Then read and parse the incoming zoom data
It looks like the Univision cameras use a protocol they call "LIMA" over the RS232, TCP, and UDP interfaces. This manual covers the a little of the LIMA protocol:
https://www.wenglor.com/medias/__secure__?mediaPK=8806510952478&attachment=true
Maybe if you can find a full LIMA manual for your camera there will be a way to ask for the current analog and digital zoom levels.
Can you infer where the zoom is from time of movement ?
Hi, I already have done that. I have shared the screen shot as well, what I get when I zoom in to camera.
I didn't realise that it was a screenshot of the info from your Arduino. Your description above the pictures only states that you receive this data but not where the data is being received or by which processor.
Is the RS485 data coming into your PC or into an Ardiono?
Which Arduino are you using?
How is everything connected together: camera, Arduino, PC?
Could you please post the full Arduino code, in code tags
The whole system is connected as follows:
I am using Arduino Uno as the brain of system.
The code is posted as under.
/*
Erstellt am: 25.07.2019
Author: Adam Wilczek
*/
#include <SPI.h>
#include "SPI_5041.h"
//https://github.com/jenesaisdiq/TMC5041/blob/master/TMC5041.cpp
int CAM_ARRAY[7];
DataOut in, out;
bool newData = false;
float zoom_level=1;
unsigned long microstep1 = 8837.5;
void Get_data() {
const byte size_CAM_ARRAY = (sizeof(CAM_ARRAY) / sizeof(CAM_ARRAY[0]));
static byte index_Serial = 0;
while (Serial.available() > 0 && newData == false){
CAM_ARRAY[index_Serial] = Serial.read();
index_Serial++;
if (index_Serial == size_CAM_ARRAY) {
if ((CAM_ARRAY[0] == 0xFF) &&
(CAM_ARRAY[1] == 0x01) &&
(CAM_ARRAY[2] == 0x00)) {
newData = true;
index_Serial = 0;
} else {
for (byte i = 0; i < size_CAM_ARRAY - 1; i++) {
CAM_ARRAY[i] = CAM_ARRAY[i + 1]; // SHIFT BYTE TO NEXT INDEX
}
index_Serial = size_CAM_ARRAY - 1;
}
}
}
}
void setup() {
// PINS
Serial.begin(9600);
pinMode(EN_PIN, OUTPUT);
digitalWrite(EN_PIN, LOW);// Chip ist aktiv
pinMode(CHIP_SELECT, OUTPUT);
digitalWrite(CHIP_SELECT, HIGH);
//SPI
SPI.setBitOrder(MSBFIRST);
SPI.setClockDivider(SPI_CLOCK_DIV8);
SPI.setDataMode(SPI_MODE3);
SPI.begin();
//
in = { 0x80, 0x00000000 };
sendData(in); //GCONF
//SpiStatusBit(out.adresse);
in = { 0xA0, 0x00000000 };
sendData(in); //RAMPMODE=0
in = { 0xC0, 0x00000000};
sendData(in); //RAMPMODE=0
// Motor 1
in = { 0xA3, 0x0000000F};// VSTART = 15
sendData(in);
in = { 0xA4, 0x00000F00};//A1=1000
sendData(in);
in = { 0xA5, 0x000FFFFF};//V1=100000
sendData(in);
in = { 0xA6, 0x00000F00};//AMAX=50000
sendData(in);
//in = { 0xA7, 0x000186A0};
in = { 0xA7, 0x001FFFFF}; // //VMAX=100000 Geschwindigkeit auf MAX
sendData(in);
in = { 0xA8, 0x000FF550}; //DMAX
sendData(in);
in = { 0xAA, 0x0000F578};//D1=1400
sendData(in);
in = { 0xAB, 0x00000020};//VSTOP=32
sendData(in);
in = { 0xAC, 0x0000000A};//TPOWERDOWN=10
sendData(in);
// Motor 2
in = { 0xC3, 0x0000000F}; // VSTART = 15
sendData(in);
in = { 0xC4, 0x0000F200}; //A1=1000
sendData(in);
in = { 0xC5, 0x000F86A0}; //V1=100000
sendData(in);
in = { 0xC6, 0x0000F200}; //AMAX=50000
sendData(in);
in = { 0xC7, 0x00000000}; //VMAX=100000
sendData(in);
in = { 0xC8, 0x0DFFF550}; //DMAX
sendData(in);
in = { 0xCA, 0x000FF578}; //D1=1400
sendData(in);
in = { 0xCB, 0x00000120}; //VSTOP=32
sendData(in);
in = { 0xCC, 0x0000000A}; //TPOWERDOWN=10
sendData(in);
//IHOLD Config delay irun ihold
// unsigned long iholdconfig = 0b 0000 0000 0000 0000 00 0011 11110 00000;
unsigned long iholdconfig = 0b00000000000000000000111111000011;
in = { 0xB0, iholdconfig};// Motor 1
sendData(in);
in = { 0xD0, iholdconfig};// Motor 2
sendData(in);
//CHOPPER Config
//sendData(0xEC,0x000101D5); //CHOPCONF: TOFF=5, HSTRT=5, HEND=3, TBL=2, CHM=0 (spreadcycle)
unsigned long chopconfig = 0b00000000000000001000000000000010;
in = { 0xEC, chopconfig};// Motor 1
sendData(in);
in = { 0xFC, chopconfig};// Motor 2
sendData(in);
// PWM Config freewheel autoscale pwm_freq pwm_grad pwm_amplitude
//unsigned long pwmconfig = 0b 0000 0000 00 01 0 1 01 11111111 11111111;
unsigned long pwmconfig = 0b00000000000101011111111111111111;
in = { 0x90, pwmconfig};
sendData(in); // PWMCONF Motor 1
in = { 0x98, pwmconfig};
sendData(in); // PWMCONF Motor 2
// Set up origins
//correctLocation();
in = { 0xA1, 0x00000000};// Motor 1 XACTUAL
sendData(in);
in = { 0xAD, 0x00000000};// Motor 1 XTARGET
sendData(in);
in = { 0xC1, 0x00000000};// Motor 2 XACTUAL
sendData(in);
in = { 0xCD, 0x00000000};// Motor 2 XTARGET
sendData(in);
}
void loop() {
Get_data(); //Read the Serial bytes coming in
if (newData) { //new data received from eLevel
newData = false;
for(int i=0;i<7;i++){
Serial.write(CAM_ARRAY[i]);}
//delay(1000);
//Zoom_Level Calculation
//if ((CAM_ARRAY[0] == 0xFF) && (CAM_ARRAY[1] == 0x01) && (CAM_ARRAY[2] == 0x00) && (CAM_ARRAY[3] == 0x20)&& (CAM_ARRAY[4] == 0x00)&& (CAM_ARRAY[5] == 0x00)&& (CAM_ARRAY[6] == 0x21))
//{
//int start_time= millis();
// }
//Camera Left Function
if ((CAM_ARRAY[0] == 0xFF) && (CAM_ARRAY[1] == 0x01) && (CAM_ARRAY[2] == 0x00) && (CAM_ARRAY[3] == 0x04)&& (CAM_ARRAY[4] == 0x1F)&& (CAM_ARRAY[5] == 0x00)&& (CAM_ARRAY[6] == 0x24))
{ signed long MicroStepp = 20* -400 *8837.5;
in = { 0xC7, 0x0007FFFF}; //VMAX=100000
sendData(in);
in = { 0xCC, 0x0000000A}; //TPOWERDOWN=10
sendData(in);
in = {0xCD, MicroStepp};
sendData(in);
delay (200);
}
//Camera Right Function
else if ((CAM_ARRAY[0] == 0xFF) && (CAM_ARRAY[1] == 0x01) && (CAM_ARRAY[2] == 0x00) && (CAM_ARRAY[3] == 0x02)&& (CAM_ARRAY[4] == 0x1F)&& (CAM_ARRAY[5] == 0x00)&& (CAM_ARRAY[6] == 0x22))
{ signed long MicroSteppp = 20* 400 *8837.5;
in = { 0xC7, 0x0007FFFF}; //VMAX=100000
sendData(in);
in = { 0xCC, 0x0000000A}; //TPOWERDOWN=10
sendData(in);
in = { 0xCD, MicroSteppp};
sendData(in);
delay (200);
}
// //Camera Up Function
else if ((CAM_ARRAY[0] == 0xFF) && (CAM_ARRAY[1] == 0x01) && (CAM_ARRAY[2] == 0x00) && (CAM_ARRAY[3] == 0x08)&& (CAM_ARRAY[4] == 0x00)&& (CAM_ARRAY[5] == 0x1F)&& (CAM_ARRAY[6] == 0x28))
{ signed long MicroStepppp = 20 * 400 *8837.5;
in = { 0xA7, 0x0001FFFFF}; // //VMAX=100000 Geschwindigkeit auf MAX
sendData(in);
in = { 0xAD, MicroStepppp};
sendData(in);
delay (200);
}
// //Camera Down Function
else if ((CAM_ARRAY[0] == 0xFF) && (CAM_ARRAY[1] == 0x01) && (CAM_ARRAY[2] == 0x00) && (CAM_ARRAY[3] == 0x10)&& (CAM_ARRAY[4] == 0x00)&& (CAM_ARRAY[5] == 0x1F)&& (CAM_ARRAY[6] == 0x30))
{ signed long MicroSteppppp = 20 * -400 *8837.5;
in = { 0xA7, 0x0001FFFFF}; // //VMAX=100000 Geschwindigkeit auf MAX
sendData(in);
in = { 0xAD, MicroSteppppp};
sendData(in);
delay (200);
}
//Stop Function
else if ((CAM_ARRAY[0] == 0xFF) && (CAM_ARRAY[1] == 0x01) && (CAM_ARRAY[2] == 0x00) && (CAM_ARRAY[3] == 0x00)&& (CAM_ARRAY[4] == 0x00)&& (CAM_ARRAY[5] == 0x00)&& (CAM_ARRAY[6] == 0x01))
{
in = { 0xC7, 0x00000000}; //VMAX=100000
sendData(in);
in = { 0xA7, 0x00000000}; // //VMAX=100000 Geschwindigkeit auf MAX
sendData(in);
in = { 0xCC, 0x0000000F}; //TPOWERDOWN=10
sendData(in);
in = { 0xCD, 0x00000000};// Motor 2 XTARGET
sendData(in);
in = { 0xC1, 0x00000000};// Motor 2 XACTUAL
sendData(in);
in = { 0xAD, 0x00000000};// Motor 1 XTARGET
sendData(in);
in = { 0xA1, 0x00000000};// Motor 1 XACTUAL
sendData(in);
}
}
}
It also contains two header files. You can find it in below zip file.
BOB-TMC-5041.zip (3.4 KB)
There should not be a decimal in an integer value. Your compiler may have truncated it?
Can you point out where in your code you are reading the RS485 values coming in from the camera?
Which Arduino are you using?
FYI, people will not download zip files. You might want to post the header in code-tags.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.

